Written and maintained by CASRAI Editorial Board
Published
On this page
In R, na.rm is an argument (often searched as “rm.na” or “na rm”) that tells a summary function whether to strip missing values (NA) before it calculates. It defaults to FALSE in mean(), sum(), median(), max(), min(), sd(), colSums() and rowMeans(), so a single NA makes the result NA; setting na.rm = TRUE drops the NAs first and summarises what is left. The spelling is always na.rm, never rm.na.
What na.rm means and when researchers need it
Research datasets almost always contain gaps: a skipped survey item, a failed assay well, a participant lost to follow-up. R stores these as NA. The R manual describes na.rm in mean() as “a logical evaluating to TRUE or FALSE indicating whether NA values should be stripped before the computation proceeds”, and the default is FALSE. The default means that if any input is unknown, the summary of all inputs is reported as unknown instead of quietly giving a number built from a subset.
That makes na.rm a methodological decision, not a typing detail. Setting it to TRUE means every function call analyses only the observed values, which is a complete-case style of handling for that single statistic. Whether that is defensible depends on why the values are missing, which no R argument can tell you. If missingness could bias your estimate, document the choice in your analysis plan and consider approaches beyond deletion; for removing whole rows rather than ignoring NAs inside one calculation, see our guide to omitting rows with NA in R, and for the opposite step of recoding, replacing NA with 0 in R.
Is it rm.na or na.rm?
It is na.rm: “NA” first, then “rm” for remove. The reversed form rm.na is a common slip, and R will not treat it as the same argument. A function such as mean(x, trim = 0, na.rm = FALSE, ...) has a ... in its signature, so a misspelt argument name is not necessarily an error, and the NA can stay in the result. Worse, sum() takes its inputs through ... itself (sum(..., na.rm = FALSE)), so a stray rm.na = TRUE is likely to be treated as one more value to add rather than as an option. Underscore or camel-case variants such as na_rm behave the same way in base R. If your output is still NA after you “added na.rm”, check the spelling first.
Install or access
Nothing needs installing beyond R itself. The functions below live in the base and stats packages, which are part of a standard R installation and attached when R starts. R is free software distributed through the Comprehensive R Archive Network at cran.r-project.org, and the function documentation quoted on this page is the R-devel manual at stat.ethz.ch/R-manual. Inside R, ?mean opens the same help page for your installed version.
Step-by-step: using na.rm in the common summary functions
The examples below use one small vector with a single missing value. Each result was worked by hand from the documented definitions: for the observed values 4, 8, 6 and 12, the sum is 30, the mean is 7.5 and the sorted middle pair 6 and 8 gives a median of 7.
- Create the data and see the default behaviour.
x = c(4, 8, NA, 6, 12)mean(x)
The result is
NA, becausena.rmisFALSEby default. - Add
na.rm = TRUEto the call.mean(x, na.rm = TRUE)
The result is
7.5, the mean of the four observed values (30 divided by 4). - Use the same argument in
sum(). The signature issum(..., na.rm = FALSE).sum(x)sum(x, na.rm = TRUE)
The first returns
NA; the second returns30. The manual notes that withoutna.rm = TRUEany NA or NaN makes the result NA or NaN. See also our guide to summation in R. - Use it in
median(), whose signature ismedian(x, na.rm = FALSE, ...).median(x, na.rm = TRUE)
The result is
7. Without it, the manual says the result is NA of the same type asx. - Use it in
max()andmin(), signaturemax(..., na.rm = FALSE).max(x, na.rm = TRUE)min(x, na.rm = TRUE)
The results are
12and4. - Use it in
sd(), signaturesd(x, na.rm = FALSE).sd(x, na.rm = TRUE)
The four observed values have a mean of 7.5 and squared deviations summing to 35; dividing by n – 1 = 3 and taking the square root gives about
3.416. Our guide to standard deviation in R covers the same trap in more detail. - For matrices and data frames, use
colSums(),colMeans(),rowSums()androwMeans(). Their signature iscolSums(x, na.rm = FALSE, dims = 1).m = matrix(c(2, 4, NA, 6, 1, NA, 3, 5), nrow = 4)colSums(m, na.rm = TRUE)rowMeans(m, na.rm = TRUE)
Here column one holds 2, 4, NA, 6 and column two holds 1, NA, 3, 5.
colSumsreturns12 9, androwMeansreturns1.5 4.0 3.0 5.5.
The data table below lists each function with its documented default and its documented behaviour with missing values.
Output and how to read it
Read the result against your count of NAs, not against the number you hoped to see. Three habits make that routine.
- Count what was dropped.
sum(is.na(x))returns the number of NAs inx, andsum(!is.na(x))the number that remain. Report the second as the n behind any mean or standard deviation computed withna.rm = TRUE. - Know that the removal is silent.
na.rm = TRUEproduces no message. A column that is 60% missing and a column that is 2% missing return equally confident-looking numbers. - Row and column summaries drop independently. The manual states for
colSums()and its relatives that “omission of missing values is done on a per-column or per-row basis”. In the matrix above, the two column sums are built from three values each, while the row means are built from one or two. Different summaries in the same table can therefore rest on different subsets of participants.
Empty and all-NA inputs
After NAs are removed there may be nothing left, and the documented results differ by function. The manual for sum() states that “the sum of an empty set is zero, by definition”, so an all-NA column summed with na.rm = TRUE gives 0, which can look like real data. For max() and min() on numeric input the empty-set results are -Inf and +Inf respectively. For median(), the manual states that if there are no values the result is NA. For sd(), “the standard deviation of a length-one or zero-length vector is NA”. An Inf or a spurious 0 in a results table is a prompt to check that a group was not entirely missing.
Functions with no na.rm argument
Not every statistical function takes na.rm. cor() is the one researchers meet most. It has no na.rm; it uses a use argument instead, whose documented values are "everything" (the default, which propagates NA), "all.obs" (an error if any NA is present), "complete.obs" (casewise deletion, with an error if there are no complete cases), "na.or.complete" and "pairwise.complete.obs". The stats documentation adds that na.rm appears only in var, where it determines the default of use. For correlation in practice, write cor(x, y, use = "complete.obs"); our cor() in R guide covers the arguments. Passing na.rm = TRUE to cor() is not a documented route.
Troubleshooting
The result is still NA after adding na.rm = TRUE
Check, in order: the spelling (na.rm, not rm.na); that the argument is inside the right call (mean(x, na.rm = TRUE), not mean(x), na.rm = TRUE); that the function actually has the argument; and that the data are really stored as NA. A column read from a file with placeholder text such as “N/A”, “-” or “missing” is character data, not NA, and na.rm will not touch the placeholders.
pmax() and pmin() still return NA
The manual for pmax() and pmin() states that they return NA if all the parallel elements are NA, even when na.rm = TRUE.
The output is unchanged
A function whose signature has no na.rm may not warn you about it. Read the signature on the help page (?function_name) rather than assuming the argument exists.
A number you did not expect for an empty group
See the empty-input rules above: a sum of nothing is 0, a maximum of nothing is -Inf, and a median or standard deviation of nothing is NA. Count the non-missing values per group before reporting.
Alternatives to na.rm
R and its documentation are free, and R itself offers several ways to handle NAs besides na.rm. The table compares the options this page’s sources document.
| Approach | Where it applies | What it does, per the R manual |
|---|---|---|
na.rm = TRUE |
mean, sum, median, max, min, sd, colSums, rowMeans | Strips NA values before the computation proceeds |
use = "complete.obs" |
cor, and other functions with a use argument |
Casewise deletion; error if there are no complete cases |
use = "pairwise.complete.obs" |
cor | Uses the cases complete for each pair of variables |
use = "everything" (default) |
cor | NA values propagate, so affected results are NA |
| Remove rows first | Whole data frame | Not an argument; see omit rows with NA in R |
Frequently asked questions
What does na.rm mean in R?
It stands for “NA remove”. It is a logical argument, TRUE or FALSE, that says whether NA values should be stripped before the computation proceeds. The default in the functions on this page is FALSE.
Is it rm.na or na.rm in R?
The argument is na.rm. rm.na is not an argument of these functions, and a misspelt name can fail to act as an option, leaving the NA in place.
Why does mean(x) return NA?
Because x contains at least one NA and na.rm defaults to FALSE. Use mean(x, na.rm = TRUE) if analysing only the observed values is appropriate for your data.
Does na.rm = TRUE work in cor()?
No. cor() has no na.rm argument; use its use argument, for example use = "complete.obs".
Is na.rm = TRUE statistically safe?
It is only as safe as your reason for the data being missing. It makes each statistic use the available values and gives no warning, so report how many values were dropped and justify the choice in your methods.
What does max() return when every value is NA and na.rm = TRUE?
For numeric input the documented empty-set result of max() is -Inf (and +Inf for min()), so check for groups with no observed values.
Sources
- R-devel manual,
mean: stat.ethz.ch/R-manual/R-devel/library/base/html/mean.html, checked 2026-11-14. - R-devel manual,
sum: stat.ethz.ch/R-manual/R-devel/library/base/html/sum.html, checked 2026-11-14. - R-devel manual,
median: stat.ethz.ch/R-manual/R-devel/library/stats/html/median.html, checked 2026-11-14. - R-devel manual,
Extremes(max, min, pmax, pmin): stat.ethz.ch/R-manual/R-devel/library/base/html/Extremes.html, checked 2026-11-14. - R-devel manual,
sd: stat.ethz.ch/R-manual/R-devel/library/stats/html/sd.html, checked 2026-11-14. - R-devel manual,
colSums: stat.ethz.ch/R-manual/R-devel/library/base/html/colSums.html, checked 2026-11-14. - R-devel manual,
cor: stat.ethz.ch/R-manual/R-devel/library/stats/html/cor.html, checked 2026-11-14. - The Comprehensive R Archive Network: cran.r-project.org, checked 2026-11-14.
Data: na.rm defaults and missing-value behaviour of common R summary functions
Compares, for eight common R functions, whether they have an na.rm argument, its default, and the documented result when NA values are present or the input is empty. Compiled by reading each function's page in the R-devel manual; every cell paraphrases the manual text for that function.
| Function | Signature as documented | na.rm default | Documented behaviour with NA or empty input |
|---|---|---|---|
| mean | mean(x, trim = 0, na.rm = FALSE, ...) | FALSE | na.rm: should NA values be stripped before the computation proceeds |
| sum | sum(..., na.rm = FALSE) | FALSE | Without na.rm = TRUE any NA or NaN gives NA or NaN; the sum of an empty set is zero |
| median | median(x, na.rm = FALSE, ...) | FALSE | With no values, or NA present and na.rm = FALSE, the result is NA of the same type as x |
| max / min | max(..., na.rm = FALSE) | FALSE | Numeric empty set: max gives -Inf, min gives +Inf; pmax/pmin return NA if all parallel elements are NA even with na.rm = TRUE |
| sd | sd(x, na.rm = FALSE) | FALSE | The standard deviation of a length-one or zero-length vector is NA |
| colSums / rowMeans | colSums(x, na.rm = FALSE, dims = 1) | FALSE | Omission of missing values is done on a per-column or per-row basis |
| cor | cor(x, y, use = ...) | No na.rm argument | Uses use=: everything (default, NA), all.obs (error), complete.obs (casewise deletion), na.or.complete, pairwise.complete.obs |
Sources
- R-devel manual: mean (accessed 2026-11-14)
- R-devel manual: sum (accessed 2026-11-14)
- R-devel manual: median (accessed 2026-11-14)
- R-devel manual: Extremes (accessed 2026-11-14)
- R-devel manual: sd (accessed 2026-11-14)
- R-devel manual: colSums (accessed 2026-11-14)
- R-devel manual: cor (accessed 2026-11-14)
Compiled by CASRAI from the sources above. Free to reuse under CC BY 4.0 with attribution.







