r - R/Splus 中具有可变长度数据的数据帧

标签 r time-series s-plus

以下在 R 中工作正常

myarray <- as.array(list(c(5,5), 9, c(4,2,2,4,6)))
mydf    <- as.data.frame(myarray)

但在 Splus 中它没有---给出错误消息:
Problem in data.frameAux.list(x, na.strings = na.st..: arguments imply differing 
 number of rows: 2, 1, 5 
Use traceback() to see the call stack

问:怎么回事?我怎样才能让它在 Splus 中工作?

编辑:我应该更清楚地说明为什么我要经历这个治疗 list 的奇怪过程。作为 data.frame .这是因为我最终想在 Splus 中做以下类似的事情:
mypos <- timeSeq("1/1/08", "1/3/08", by = "days")
myts <- timeSeries(data = mydf, positions = mypos)

我猜现在最好的可行选择是建立一个列表,如:
mytshack <- list(mypos, as.list(myarray))

但这很笨拙,我想获得 timeSeries 的功能如果可能的话

最佳答案

评论后编辑。

SPlus 不允许将向量作为数据帧中的值,这与 R 不同。您必须为此使用一个列表,我只是这样做:

day <- c("1/1/2000","1/2/2000","1/3/2000")
names(myarray) <- day

它允许以通常的方式访问数据:
> myarray[["1/1/2000"]]
[1] 5 5

鉴于您确认这实际上是您想要的,以及有关数据集的额外信息,请尝试以下操作:
myarray <- as.array(list(c(5,5), 9, c(4,2,2,4,6)))
mydf <- as.matrix(myarray)
colnames(mydf) <- "myarray"


mypos <- timeSeq("1/1/08", "1/3/08", by = "days")
myts <- timeSeries(data = mydf, positions = mypos)
seriesData(myts)

这适用于 SPlus。 timeSeries 需要一个矩形对象,而 as.rectangular 不能处理数组。所以转换为矩阵就可以了。不过,我只是使用包 timeSeries在 R 中而不是在 SPlus 中将其组合在一起。

关于r - R/Splus 中具有可变长度数据的数据帧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5342448/

相关文章:

python - 在Python中合并时间序列数据帧

c - R、.Call 函数和 SEXP 结构

r - Left_join : Error: cannot allocate vector of size "small" Mb

r - 在 R 中的列数据框中拆分字符串并为子字符串创建其他列

r - S-PLUS死了吗?

r - s+(或 R)中的机器学习库?

r - R中的环视正则表达式模式

python - 是否可以使用 FB Prophet 进行多元多步预测?

javascript - 时间序列数据的线性回归