Section 17 Vector Operation: NA
Operation with NA
cannot be decided, so the result is NA
17.1 Missing values: Operation
Many functions will return NA
if a numeric vector includes NA
Most functions can include na.rm=TRUE
for removing NA
values prior to applying the function.
17.6 Numeric vector with Functions
Note that many functions will return NA
if a numeric vector includes NA
and you call a function without excluding NA
explicitly.
x <- c(1, 2, NA, 10, 3)
sum(x)
mean(x)
sum(x, na.rm = TRUE)
mean(x, na.rm = TRUE)
mean(na.omit(x))
sqrt(x)
y <- c(1, 2, NaN, NA, 4)
sum(y)
mean(y)
sum(y, na.rm = TRUE)
mean(y, na.rm = TRUE)
x
y
x + y
x - y
x * y
x/y