I have a data frame with 2 columns, the first containing the dates and the second containing the time in the format:
date time
[1,] "2003-10-03" "22:32:00"
[2,] "2003-10-05" "17:43:06"
[3,] "2003-10-10" "18:45:56"
[4,] "2003-11-12" "17:07:16"
[5,] "2003-11-13" "12:48:04"
[6,] "2003-11-13" "18:17:57"
I would like to create several histograms of this data, considering the number of events per year, in months and at a particular hour of the day.
Throughout the year this easy
hist(as.Date(df[,1]), "years")
Now, to get the number of events per month (excluding the year), I used:
months = c("January", "February", "March",
"April", "May", "June", "July",
"August", "September", "October",
"November", "December")
tb <- table(factor(months.Date(dt), levels=months)
barplot(tb)
Questions:
- Is there a better way to make a histogram per month?
- How can I do the same during the day (hourly bins are sufficient)?
thank
source
share