r - using tapply() with strptime() formatted date -
i want calculate daily mean set of values taken periodically throughout day, number of different days in info set. tapply() great, when date factor
> data$data <- as.factor(data$date) > str(data$date) factor w/ 55 levels "01/05/2014","02/05/2014",..: 3 3 3 3 3 3 3 3 3 3 ... > tapply(data$humidity,data$date, fun = mean) 01/05/2014 02/05/2014 03/04/2014 03/05/2014 04/04/2014 04/05/2014 05/04/2014 05/05/2014 06/04/2014 99.96875 100.00000 96.65833 99.80625 84.14375 89.56042 93.75833 39.58750 87.55000 this gives me want these dates no longer in chronological order have done factor.
instead have tried using strptime() recognised date format r. starting 1 time again beginning....
> data$date<-strptime(data$date, format="%d/%m/%y") > str(data$date) posixlt[1:2586], format: "2014-04-03" "2014-04-03" "2014-04-03" "2014-04-03" "2014-04-03" "2014-04-03" ... > tapply(data$humidity,data$date, fun = mean) error in index[[i]] : subscript out of bounds but next error message? know why isn't working?
you can convert date factor when tapply
tapply(data$humidity,factor(data$date), fun = mean) the tapply function requires factor.
r strptime tapply
No comments:
Post a Comment