Section 32 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.
32.1 Example: Numeric vector
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.
<- c(1, 2, NA, 10, 3)
x sum(x)
mean(x)
sum(x, na.rm=TRUE)
mean(x, na.rm=TRUE)
mean(na.omit(x))
sqrt(x)
<- c(1, 2, NaN, NA, 4)
y sum(y)
mean(y)
sum(y, na.rm=TRUE)
mean(y, na.rm=TRUE)
x
y+ y
x - y
x * y
x / y x
32.2 Example: Logical vector
<- c(T, F, NA, TRUE, FALSE)
x sum(x)
sum(x, na.rm=TRUE)
<- c(T, F, NaN, NA, TRUE, FALSE)
y sum(y)
sum(y, na.rm=TRUE)