The following开发者_如何学Python works fine in R
myarray <- as.array(list(c(5,5), 9, c(4,2,2,4,6)))
mydf <- as.data.frame(myarray)
But in Splus it does not---giving the error message:
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
Q: What's going on? How can I get this to work in Splus?
EDIT: I should make clearer why I'm going through this strange process of treating a list
as a data.frame
. It's because I'd eventually like to do something like the following in Splus:
mypos <- timeSeq("1/1/08", "1/3/08", by = "days")
myts <- timeSeries(data = mydf, positions = mypos)
The best feasible option right now, I guess, would be to build a list like:
mytshack <- list(mypos, as.list(myarray))
But this is clunky and I'd like to get the functionality of a timeSeries
if possible
EDITED after comments.
SPlus does not allow vectors as values in a dataframe, contrary to R. You'll have to use a list for that, and I'd simply do :
day <- c("1/1/2000","1/2/2000","1/3/2000")
names(myarray) <- day
which allows access to the data the usual way :
> myarray[["1/1/2000"]]
[1] 5 5
Given your confirmation this is actually what you want, and the extra information about the dataset, try this :
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)
This works in SPlus. timeSeries needs a rectangular object, and as.rectangular can't deal with arrays. So converting to a matrix will do. Still, I'd just use the package timeSeries
in R instead of hacking it together in SPlus.
精彩评论