在 R 中计算标准偏差时忽略 NA 值
Ignore NA values when computing Standard Deviation in R
我在R中使用标准偏差sd()函数。我的问题是如何忽略给定数据集中的NA值,
使用示例:
x <- c(0.23,0.26,0.77,0.44,0.35,NA)
sd(x)
它returns NA,有没有办法忽略NA值。
调用sd()
时使用na.rm=TRUE
:
R> l <- c(0.23,0.26,0.77,0.44,0.35,NA)
R> sd(l)
[1] NA
R> sd(l, na.rm=TRUE)
[1] 0.217371
R>
我在R中使用标准偏差sd()函数。我的问题是如何忽略给定数据集中的NA值, 使用示例:
x <- c(0.23,0.26,0.77,0.44,0.35,NA)
sd(x)
它returns NA,有没有办法忽略NA值。
调用sd()
时使用na.rm=TRUE
:
R> l <- c(0.23,0.26,0.77,0.44,0.35,NA)
R> sd(l)
[1] NA
R> sd(l, na.rm=TRUE)
[1] 0.217371
R>