na.rm=T in R

Follow the example to see the use of na.rm=T in R

> x=c(0, 1, 1, 2, 3, 5, 8) #vector
> x
[1] 0 1 1 2 3 5 8
> mean(x)
[1] 2.857143

Now, introduce a NA value in our vector.

> x=c(0, 1, 1, 2, 3, 5, 8,NA)
> mean(x)
[1] NA # mean does not work!

> mean(x,na.rm=T) #Try removing NA for mean.
[1] 2.857143

Leave a Comment

Your email address will not be published. Required fields are marked *