Search code examples
rnaconfidence-interval

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. I have na.rm = T but doesn't work.

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'

From what I can tell it is because the CI function doesn't support NA.RM. If I do not use NA,RM I only NA for all the interval values

Does anyone know a work around?


Solution

  • Just wrap your vector in na.omit():

    > CIvector <- CI(na.omit(myvector))
    > CIvector
       upper     mean    lower 
    60.85270 60.71467 60.57663