I have an xts object that has intraday data:
head(stocks[,1])
SMH.close
2009-01-02 09:31:00 17.66
2009-01-02 09:32:00 17.66
2009-01-02 09:33:00 17.64
2009-01-02 09:34:00 17.60
2009-01-02 09:35:00 17.58
2009-01-02 09:36:00 17.63
I want to perform various analytics on intraday data, but operations should not cross the boundaries of the day. So I want to split the data by date (ignoring the time). So I extracted the index and saved the unique date values:
y <- index(stocks)
x <- strptime(y, format="%Y-%m-%d")
uniquedates <- unique(x)
Now I would like to do something similar to the example in the split section
> g <- airquality$Month
> l <- split(airquality, g)
Here, security data is broken down into a list object by the value of the Month column. I'm not sure how to do something like this, since a date is an index in my case, not a data column. I tried but got an error.
> split(stocks, uniquedates)
Error in args[[i]] : subscript out of bounds
There may be a cleaner way to achieve what I want to do. I would really appreciate your help.
source
share