I have a data frame dfthat contains "messages". Each line is a message. Each message has a timestamp df$messagedatein POSIXct format %Y-%m-%d %H:%M:%S. Example:
> head(df)
messageid user.id message.date
123 999 2011-07-17 17:54:27
456 888 2011-07-19 16:56:50
(The following is the version of dput()'ed):
df <- structure(list(messageid = c(123L, 456L), user.id = c(999L, 888L),
message.date = structure(c(1310950467, 1311119810), class = c("POSIXct",
"POSIXt"), tzone = "")), .Names = c("messageid", "user.id",
"message.date"), row.names = c(NA, -2L), class = "data.frame")
How to create a data frame with the total number of messages per day? Example:
day message.count
2011-07-17 1
2011-07-18 0
2011-07-19 1
Instead of not including dates without messages, I want to make sure that message.countzero is set for those days .
What I have done so far: I extracted part of the calendar day message.dateby doing:
df$calendar.day<-as.POSIXct(strptime(substr(df$message.date,1,10),"%Y-%m-%d",tz="CST6CDT"))
> head(df$calendar.day)
[1] "2011-07-17 CDT" "2011-07-18 CDT" "2011-07-19 CDT"
: daterange < - seq (min (df $calendar.day), max (df $calendar.day), by = "day" )