计算基础统计量
Use one of these functions as appropriate, assuming that x and y are vectors:
mean(x)median(x)
sd(x)
var(x)
cor(x, y)
cov(x, y)
Does an NA in your data invalidate the statistic? If yes,
then R is doing the right thing. If not, you can override this behavior by setting
na.rm=TRUE, which tells R to ignore the NA values:
> x <- c(0,1,1,2,3,NA)
> mean(x, na.rm=TRUE)
[1] 1.4
> sd(x, na.rm=TRUE)
[1] 1.140175
then R is doing the right thing. If not, you can override this behavior by setting
na.rm=TRUE, which tells R to ignore the NA values:
> x <- c(0,1,1,2,3,NA)
> mean(x, na.rm=TRUE)
[1] 1.4
> sd(x, na.rm=TRUE)
[1] 1.140175