I\'m very new to R (moving over from SPSS). I\'m using RStudio on a Mac running Mavericks. Please answer my question in words of 2 syllables as this is my first real attempt a
unfortunately, as.numeric makes an implicit coercion, which leads to wrong answers. don't imply it on factors.
Hello Rnovice unfortunatly there are several errors... Lets resolve them one by one:
> mean(as.numeric(data_Apr_Jun$hold_time,NA.rm=TRUE))
[1] NA
This is because you use na.rm in a wrong manner:
it should be
mean(as.numeric(data_Apr_Jun$hold_time),na.rm=TRUE)
na.rm is an argument of mean, not of as.numeric (caution with the brackets)na.rm R is case sensitive==================================================================================
> data_Apr_Jun$hold_time[data_Apr_Jun$hold_time=="NA"]<-0
R does not allow comparison with NA as i pointed our here:
Something weird about returning NAs
What you mean is
data_Apr_Jun$hold_time[which(is.na(data_Apr_Jun$hold_time))] <- 0
One more remark =="NA" is comparing with a string "NA". Try is.na("NA") and is.na(NA) to see the difference.
==================================================================================
colMeans(data_Apr_Jun$hold_time)
Error in colMeans(data_Apr_Jun$hold_time) :
'x' must be an array of at least two dimensions
try data_Apr_Jun$hold_time and you will see, that it returns a vector. This is why a colwise mean (computed by colMeans) makes no sence.
Hope the rest is understandable/solveable with these hints.
One very importent thing that you already realized:
Use R! you are on the right track!