Hi, Try: #using the same `data` res1 <- as.data.frame(table(with(dat,cut(Date,breaks=seq(as.POSIXct("2013-01-01 00:00:00"),max(Date)+3600,by='1 hour')))))
A.K. Hi A.K. Thank you very much! It worked!! Just another quick follow-up question: res <- as.data.frame(table( with(dat,cut(Date,breaks=seq(min(Date),max(Date)+3600,by= '1 hour'))))) Is it possible to set the min in the seq() to a specific date-time say 2013-01-01 00:00:00? Thank you again for your help! Map On Thursday, February 6, 2014 5:34 PM, arun <smartpink...@yahoo.com> wrote: HI Map, I am not sure what you really wanted. Perhaps, this helps: dat <- structure(list(Date = c("2014-01-01 00:00:00", "2014-01-02 11:00:00", "2014-01-02 22:00:00", "2014-01-03 03:00:00", "2014-01-01 00:00:00", "2014-02-02 11:00:00", "2014-02-02 22:00:00", "2014-02-03 03:00:00", "2014-02-01 00:00:00", "2014-03-01 11:00:00", "2014-03-02 22:00:00", "2014-03-03 03:00:00", "2014-03-01 00:00:00", "2014-03-01 11:00:00", "2014-03-02 22:00:00", "2014-01-03 03:00:00")), .Names = "Date", class = "data.frame", row.names = c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16")) dat$Date <- as.POSIXct(dat$Date) res <- as.data.frame(table( with(dat,cut(Date,breaks=seq(min(Date),max(Date)+3600,by= '1 hour'))))) A.K. Hi AK, Thanks for the tips! But it doesn't seem to work for some reasons. Basically I want to do a time series analysis and I heard that it is actually very easy to perform hourly count, e.g. count the number of occurrence hourly when the variable is in date-time format like this: YYYY-MM-DD HH:MM:SS. I was thinking a 'long' way (sorry for this if it sounds stupid :p) by dividing my data into say 1000 24-hr (i.e. one day) sections, count them all them merge... Anyway, could you give me more advice on this please? Thanks! Map On Wednesday, February 5, 2014 10:59 AM, arun <smartpink...@yahoo.com> wrote: Hi, Try: data.frame(table(dat$Date)) A.K. Hi guys, I have some 20,000 observations like this: Date 2014-01-01 00:00:00 2014-01-02 11:00:00 2014-01-02 22:00:00 2014-01-03 03:00:00 I want to perform an hourly count (e.g. the frequency occur at each hour for a specific date) so the result would look like this: Date Frequency 2014-01-01 00:00:00 1 2014-01-01 01:00:00 1 2014-01-01 02:00:00 1 2014-01-01 03:00:00 1 Any suggestions? Thanks! ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.