I have an S4 class list (called vi2). This is the first segment of it:
- @variables: chr [1:7]
- @vImplist: list of 400
- $1: Formal class '.vImp' with 2 slots
- @Variables: chr [1:7]
- @vImp: 'data.frame': 7 bs. of 3 variables:
- $variables:Factor w/ 7 levels
- $Ctest: num [1:7]
- $Atest: num [1:7]
- $variables:Factor w/ 7 levels
- $2: Formal class '.vImp' with 2 slots
- @Variables: chr [1:7]
- @vImp: 'data.frame': 7 bs. of 3 variables:
- $variables:Factor w/ 7 levels
- $Ctest: num [1:7]
- $Atest: num [1:7]
- $variables:Factor w/ 7 levels
- $1: Formal class '.vImp' with 2 slots
In total there are 400 classes of '.vImp' which are all in the same format. What I am attempting to do is extract the '@vImp: data. frame' for each class and merge them into a new dataframe. I able am to do this individually with the following line:
vic = as.data.frame(vi2@vImplist$'1'@vImp)
This produces the data.frame with the correct information for that class. However when I try performing this for all 400 classes at once, it fails.
vic = as.data.frame(vi2@vImplist$'1:400'@vImp)
Error in as.data.frame(vi2@vImplist$'1:400'@vImp) : trying to get slot "vImp" from an object of a basic class ("NULL") with no slots.
I also tried using a loop to complete the task. However, this also failed with the same error:
for (i in seq(from = 1, to = 1, by = 1)) {
vic = as.data.frame(vi2@vImplist$'[i]'@vImp)
output <- rbind(newdf,vic)
}
Does anyone have any suggestions for what the problem might be?