R: ddply function applied to certain months obtained from date field -
can functions applied month/year combinations of date field in ddply? want figure mean (among other functions) specifying month/year.
monthlysummary <- ddply(tempdata, .(date, siteid, substrateid), summarize, monthlymean=mean(temp_c))
not sure mean "only month/year combinations" perhaps subset
want, thought might asking summarization month. assuming date field of class date:
monthlysummary <- ddply(tempdata, .(format(date, "%m" ), summarize, monthlymean=mean(temp_c))
if it's not date class variable, maybe should make one:
tempdata$date2 <- as.date(tempdata$date, "%d/%m/%y") # or format
and if wanted site , substrate month then:
monthlysummary <- ddply(tempdata, .( format(date, "%m" ), siteid, substrateid), summarize, monthlymean=mean(temp_c))
other date-aggregation options besides format.posixt
include functions in package:lubridate , 'yearmon' class supported in package:zoo. exaple offered above lump event occurring in january of year. if wanted year-month distinction maintained need include in format-string: format(date, "%m-%y")
.
Comments
Post a Comment