我想将我的大xts对象拆分为包含原始对象的所有观察的常规一秒期间的列表。目标是将每个列表元素发送到集群上的节点进行处理。
我提出了这个解决方案,非常精细。我想知道这段代码是否可以简化:
library(xts)
set.seed(123)
myts = xts(1:10000, as.POSIXlt(1366039619, ts="EST", origin="1970-01-01") + rnorm(10000, 1, 100))
# insure we have at least one observation per second
secs = seq(trunc(index(head(myts, 1))), trunc(index(tail(myts, 1))), by="s")
# generate second periods endpoints
myts = merge(myts, secs, fill=na.locf)
myts.aligned = align.time(myts, 1)
myts.ep = endpoints(myts.aligned, "seconds", 1)
# split large xts object in list of second periods
myts.list = lapply(1:(length(myts.ep)-1), function(x, myts, ep) { myts[ep[x]:ep[x+1],] }, myts, myts.ep)
# call to parLapply here...
答案 0 :(得分:2)
我认为这可以满足您的需求:
split(myts, "secs")
它将创建一个列表,其中每个组件是1秒非重叠数据。
请参阅?split.xts