[英]Ignoring NA for confidence interval (CI)
I am wanting to get the confidence intervals for a vector in R but I have a NA values and want to ignore the NA.我想获得 R 中向量的置信区间,但我有一个 NA 值并想忽略 NA。 I have
na.rm = T
but doesn't work.我有
na.rm = T
但不起作用。
Here is my vector and what I have tried:这是我的向量和我尝试过的内容:
myvector <- c(60.558,60.680,60.757,60.750,60.708, 60.738, NA, 61.103,60.702,60.436)
CIvector <- CI(myvector,na.rm=T)
I get an error message:我收到一条错误消息:
'Error in 1 - ci : non-numeric argument to binary operator'
'1 - ci 中的错误:二元运算符的非数字参数'
From what I can tell it is because the CI function doesn't support NA.RM.据我所知,这是因为 CI 功能不支持 NA.RM。 If I do not use NA,RM I only NA for all the interval values
如果我不使用 NA,RM 我只对所有区间值使用 NA
Does anyone know a work around?有谁知道解决方法?
Just wrap your vector in na.omit()
:只需将您的向量包装在
na.omit()
中:
> CIvector <- CI(na.omit(myvector))
> CIvector
upper mean lower
60.85270 60.71467 60.57663
Using complete.cases
.使用
complete.cases
。 There is no na.rm
argument in Rmisc::CI
Rmisc::CI
中没有na.rm
参数
Rmisc::CI(myvector[complete.cases(myvector)])
# upper mean lower
#60.85270 60.71467 60.57663
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.