Quantcast

how to store object without loosing their class property

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

how to store object without loosing their class property

Immanuel-2
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]]))
-----------

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: how to store object without loosing their class property

Kenn Konstabel
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 <[hidden email]> 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]]))
> -----------
>
> ______________________________________________
> [hidden email] 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.
>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: how to store object without loosing their class property

Immanuel-2
great! thanks

2011/5/31 Kenn Konstabel <[hidden email]>:

> 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 <[hidden email]> 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]]))
>> -----------
>>
>> ______________________________________________
>> [hidden email] 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.
>>
>

______________________________________________
[hidden email] 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.
Loading...