I have some data in CSV like:
"Timestamp", "Count"
"2009-07-20 16:30:45", 10
"2009-07-20 16:30:45", 15
"2009-07-20 16:30:46", 8
"2009-07-20 16:30:46", 6
"2009-07-20 16:30:46", 8
"2009-07-20 16:30:47", 20
I can read it into R using read.cvs. I'd like to plot:
- Number of entries per second, so:
"2009-07-20 16:30:45", 2 "2009-07-20 16:30:46", 3 "2009-07-20 16:30:47", 1
- Average value per second:
"2009-07-20 16:30:45", 12.5 "2009-07-20 16:30:46", 7.333 "2009-07-20 16:30:47", 20
- Same as 1 & 2 but then by Minute and then by Hour.
Is there some way to do this (collect by second/min/etc & plot) in R?
Averaging the data is easy with the plyr package.
To do the same thing by minute or hour, then you need to add fields with that info.
Read your data, and convert it into a zoo object:
Note that this will show warnings because of non-unique timestamps.
Task 1 using
aggregate
withlength
to count:Task 2 using
aggregate
:Task 3 can be done the same way by aggregating up to higher-order indices. You can call
plot
on the result from aggregate: