mean
mean
is a function that calculates the average of a vector of values.
Examples
How do I get the average of the values in a vector when some of the values are: NA
, NaN
?
Click to see solution
Many R functions have the na.rm
argument available.
This argument is "a logical value indicating whether NA values should be stripped before the computation proceeds. (Citation)
mean(c(1,2,3,NaN), na.rm=T)
[1] 2
mean(c(1,2,3,NA), na.rm=T)
[1] 2
mean(c(1,2,NA,NaN,4), na.rm=T)
[1] 2.333333