[R] how to store object without loosing their class property

Immanuel B mane.desk at googlemail.com
Tue May 31 16:11:51 CEST 2011


great! thanks

2011/5/31 Kenn Konstabel <lebatsnok at gmail.com>:
> use "list" instead of "c":
>
> models <- list(model,model)
> sapply(models, class)
>
> #      [,1]          [,2]
> # [1,] "svm.formula" "svm.formula"
> # [2,] "svm"         "svm"
>
> For understanding what c does in your case:
>
> c(list(first=1, second=2), list(third=3, fourth=4))
> # compare this with list(list(first=1, second=2), list(third=3, fourth=4))
>
> Kenn
>
> On Tue, May 31, 2011 at 4:43 PM, Immanuel B <mane.desk at googlemail.com> wrote:
>> Hello all,
>>
>> I'm trying to store some objects (class = "svm") , but if I use a list
>> the objects get somehow converted and I can't retrieve them as objects
>> of type "svm".
>> So how to I properly store objects of that kind?
>>
>> best regards
>> -----------
>>
>> library(e1071)
>>
>> data(iris)
>> attach(iris)
>>
>> ## classification mode
>> # default with factor response:
>> model <- svm(Species ~ ., data = iris)
>>
>>
>> print(class(model))
>> models = list()
>> models = c(model,model)
>>
>> print(class(models[[1]]))
>> -----------
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>



More information about the R-help mailing list