I have problem with creating list of models.
Suppose I’ve created model:
> rp <- rpart(V41 ~ ., data=learnData, method="class")
If I’m creating list straight, thats OK:
> ll <- list(rp, rp, rp)
> class(ll[[1]])
[1] "rpart"
> class(ll[[2]])
[1] "rpart"
> class(ll[[3]])
[1] "rpart"
But if I’m trying to append model to already created list,
models changing their class to data.frame:
> ll <- list(rp)
> ll <- append(ll, rp)
> class(ll[[1]])
[1] "rpart"
> class(ll[[2]])
[1] "data.frame"
What’s a reason of this behavior and how can I append model to list?
The function
appendis used to add elements to a vector.To add elements to a list, use
list. Try:You should now have a list of
lmobjects:To append to an existing list, use
listas follows: