-2
 [9982] "2012-10-22 12:10:21 EDT" "2012-10-22 02:48:09 EDT" "2012-10-22 13:13:51 EDT"
 [9985] "2012-10-22 14:24:23 EDT" "2012-10-22 10:49:54 EDT" "2012-10-22 09:49:32 EDT"

Given is the R print-out of the data I am working with. Essentially, I have one massive column of data with dates and times in the above format.

I have not been able to figure out how to take this data and create a time series graph in R. I am interested in potentially binning the data by some arbitrary time frame (such as 10min, 30min, or 60min), and graphing the results over time.

Any help on this issue is greatly appreciated! Thanks for reading.

Gregor Thomas
  • 136,190
  • 20
  • 167
  • 294
  • 1
    A little more detail would help. Are there also data values associated with these datetimes in another column? – Dinre Feb 26 '13 at 18:02
  • Graphing *what*? What do the other columns contain? – A5C1D2H2I1M1N2O1R2T1 Feb 26 '13 at 18:02
  • You really need to give sample data else it's difficult for others to help. – CHP Feb 26 '13 at 18:28
  • Do you just want points on a timeline? Also, please consider using `dput(head(yourdata))` to give us your data so we can copy/paste (see [R how-to reproducible example](http://stackoverflow.com/a/5963610/903061)) – Gregor Thomas Feb 26 '13 at 18:44
  • [Try something.](http://whathaveyoutried.com) Stop being a help vampire. –  Feb 26 '13 at 19:15

1 Answers1

0

You don't provide much at all in the way of sample data to really give us an idea of what you want to achieve, but here's something that might get you started. Ultimately, what the recommendation comes down to is to convert your data to "xts" and use period.apply to aggregate and plot your data at "arbitrary" time frames.

Here's some sample data, first as a data.frame of random values collected every 11 minutes starting at 2012-10-22 12:10:21 EDT, then converted to xts:

set.seed(1)
temp <- data.frame(date = seq(as.POSIXct("2012-10-22 12:10:21 EDT", tz="EDT"), 
                              length.out = 100, by = "11 min"),
                   values = rnorm(100))
library(xts)
x.temp <- xts(temp[-1], temp[, 1])
head(x.temp)
#                         values
# 2012-10-22 12:10:21 -0.6264538
# 2012-10-22 12:21:21  0.1836433
# 2012-10-22 12:32:21 -0.8356286
# 2012-10-22 12:43:21  1.5952808
# 2012-10-22 12:54:21  0.3295078
# 2012-10-22 13:05:21 -0.8204684

Here, we're going to aggregate, arbitrarily, the sum for every 93 minutes that elapsed.

my93minAgg <- period.apply(x.temp, 
                           INDEX = endpoints(x.temp, on = "mins", k = 93), 
                           FUN = sum)
my93minAgg
#                         values
# 2012-10-22 13:16:21  0.3133101
# 2012-10-22 14:55:21  1.1543989
# 2012-10-22 16:23:21  2.1290954
# 2012-10-22 18:02:21  0.5205041
# 2012-10-22 19:30:21 -0.6007850
# 2012-10-22 21:09:21  1.5058904
# 2012-10-22 22:37:21  0.9999036
# 2012-10-23 00:16:21  1.1553448
# 2012-10-23 01:44:21  1.9799783
# 2012-10-23 03:23:21 -1.7152471
# 2012-10-23 04:51:21  2.9882778
# 2012-10-23 06:19:21  0.4580653

Here's how you would plot it:

plot(my93minAgg, main = "My 93 Minute Aggregation")
A5C1D2H2I1M1N2O1R2T1
  • 190,393
  • 28
  • 405
  • 485