[R] mean for vector with NA
bad2101 at columbia.edu
bad2101 at columbia.edu
Thu Aug 21 21:15:14 CEST 2008
I am trying to find the mean for the elements in the vector
Incubation=as.POSIXlt(OnsetTime)-as.POSIXlt(MealTime)
where
OnsetTime=c(NA,"1940-04-19 00:30","1940-04-19 00:30","1940-04-19
00:30",NA,"1940-04-18 22:30","1940-04-18 22:30","1940-04-19
02:00","1940-04-19 01:00","1940-04-18 23:00",NA,NA,NA,"1940-04-19
02:00",NA,"1940-04-19 10:30","1940-04-19 00:30","1940-04-18
22:15",NA,"1940-04-18 22:00","1940-04-19 01:00","1940-04-18
23:00",NA,"1940-04-18 21:45",NA,"1940-04-18 21:45","1940-04-19
01:00",NA,"1940-04-18 23:00",NA,"1940-04-18 21:00","1940-04-19
01:00","1940-04-19 01:00",NA,NA,"1940-04-18 21:15",NA,"1940-04-18
23:30","1940-04-19 01:00","1940-04-18 21:30",NA,"1940-04-19
02:30","1940-04-19 02:00","1940-04-18 21:30",NA,NA,"1940-04-19
00:30","1940-04-19 01:00","1940-04-18 22:30",NA,NA,"1940-04-18
15:00",NA,"1940-04-19 00:00","1940-04-18 23:00",NA,"1940-04-18
22:30","1940-04-19 01:00","1940-04-19 02:30","1940-04-18
23:30",NA,NA,NA,NA,"1940-04-19 01:00","1940-04-19
00:30",NA,NA,NA,"1940-04-19 00:30","1940-04-19 01:00","1940-04-19
00:00",NA,"1940-04-19 02:15","1940-04-18 23:00")
MealTime=c(NA,"1940-04-18 20:00","1940-04-18 18:30","1940-04-18
18:30",NA,"1940-04-18 19:30","1940-04-18 19:30","1940-04-18
19:30","1940-04-18 22:00","1940-04-18 19:00",NA,NA,NA,"1940-04-18
19:30",NA,NA,NA,NA,NA,NA,"1940-04-18 22:00",NA,NA,NA,NA,NA,"1940-04-18
22:00",NA,NA,"1940-04-18 22:00",NA,"1940-04-18 22:00","1940-04-18
22:00",NA,NA,NA,NA,NA,"1940-04-18 22:00",NA,NA,NA,NA,NA,"1940-04-18
22:00",NA,NA,"1940-04-18 19:00",NA,NA,NA,"1940-04-18
11:00",NA,NA,NA,NA,NA,"1940-04-18 22:00","1940-04-18
19:30","1940-04-18 19:30",NA,NA,NA,NA,"1940-04-18
22:00",NA,"1940-04-18 19:30","1940-04-18 19:30",NA,NA,"1940-04-18
19:30","1940-04-18 19:30","1940-04-18 22:00",NA,NA)
I have tried
mean(Incubation)
and
mean(as.numeric(Incubation))
but I think that, since there are so many NA values in Incubation, R
gives a mean value of NA. Is there any way of either extracting all
numeric values (i.e. all non-NA values) from the Incubation vector, or
finding the mean value of only the numeric values in the Incubation
vector?
Brian
More information about the R-help
mailing list