time series - R creating timeseries with existing dates from file -
i'm trying create time series plot using r obtain dates rest request , want grouping , count date occurrences on 1 week interval. followed examples of ts() in r , tried plots, worked great. couldn't find examples shows how create date aggregation based on existing data. can point me in proper direction?
this sample of parsed rest data:
rest response excerpt ....
"2014-01-16t14:51:50.000-0800" "2014-01-14t15:42:55.000-0800" "2014-01-13t17:29:08.000-0800" "2014-01-13t16:19:31.000-0800" "2013-12-16t16:56:39.000-0800" "2014-02-28t08:11:54.000-0800" "2014-02-28t08:11:28.000-0800" "2014-02-28t08:07:02.000-0800" "2014-02-28t08:06:36.000-0800" .... sincerely, code b.
you can define date "as.date" , create time series "xts", allows merging period of time.
library(xts) rest$date <- as.date(rest$date, format="%y-%m-%d") rest$variable <- seq(0,2.4,by=.3) ts <- xts(rest[,"variable"], order.by=rest[,"date"]) > to.monthly(ts) ts.open ts.high ts.low ts.close dec 2013 1.2 1.2 1.2 1.2 xan 2014 0.6 0.9 0.0 0.0 feb 2014 1.5 2.4 1.5 2.4 > to.weekly(ts) ts.open ts.high ts.low ts.close 2013-12-16 1.2 1.2 1.2 1.2 2014-01-16 0.6 0.9 0.0 0.0 2014-02-28 1.5 2.4 1.5 2.4 not sure if needed. it?
r time-series rscript
No comments:
Post a Comment