Hello, Rnovice, unfortunately, there are several errors ... Allows you to solve them in turn:
> mean(as.numeric(data_Apr_Jun$hold_time,NA.rm=TRUE)) [1] NA
This is due to the misuse of na.rm : it should be
mean(as.numeric(data_Apr_Jun$hold_time),na.rm=TRUE)
na.rm is a mean argument, not as.numeric (caution with brackets)na.rm R case sensitive
==================================================== ==================================
> data_Apr_Jun$hold_time[data_Apr_Jun$hold_time=="NA"]<-0
R does not allow comparison with NA , as I pointed out here: Something strange regarding the return of NAs
You mean
data_Apr_Jun$hold_time[which(is.na(data_Apr_Jun$hold_time))] <- 0
Another note =="NA" compared with the 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 the average value (calculated by colMeans ) does not matter.
Hope the rest is clear or accessible with these hints. One very important thing that you already understood:
Use R! You are on the right track!
source share