Variable-length data frames in R / Splus

The following 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, this does not indicate --- an 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 is going on? How can I get this to work in Splus?

EDIT: I have to clarify why I'm going through this weird process of handling list as data.frame . This is because in the end I would like to do something like Splus:

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

The best possible option right now, I think, would be to create a list like:

 mytshack <- list(mypos, as.list(myarray)) 

But this is inconvenient, and I would like to get timeSeries functionality, if possible

+4
source share
1 answer

EDITED after the comments.

SPlus does not allow vectors as values ​​in a data frame, unlike R. You would need to use a list for this, and I would just do:

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

which allows access to data in the usual way:

 > myarray[["1/1/2000"]] [1] 5 5 

Given your confirmation, this is actually what you want and additional information about the dataset, try the following:

 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 cannot deal with arrays. Therefore, there will be a transformation into a matrix. However, I would just use the timeSeries package in R instead of hacking it together in SPlus.

+3
source

Source: https://habr.com/ru/post/1344146/


All Articles