[R] Extract information from S4 object

David Winsemius dwinsemius at comcast.net
Mon Feb 22 15:34:58 CET 2010


On Feb 22, 2010, at 8:05 AM, Jay wrote:

> The function prediction() returns this:
>
> Formal class 'performance' [package "ROCR"] with 6 slots
>  ..@ x.name      : chr "Cutoff"
>  ..@ y.name      : chr "Accuracy"
>  ..@ alpha.name  : chr "none"
>  ..@ x.values    :List of 1
>  .. ..$ : Named num [1:89933] Inf 2.23 2.22 2.17 2.16 ...
>  .. .. ..- attr(*, "names")= chr [1:89933] "" "36477" "56800"
> "41667" ...
>  ..@ y.values    :List of 1
>  .. ..$ : num [1:89933] 0.5 0.5 0.5 0.5 0.5 ...
>  ..@ alpha.values: list()
>
> Now, since I want to match each prediction with its original case, I
> need to extract the names, i.e. the information in "- attr(*,
> "names")= chr [1:89933] "" "36477" "56800" "41667" ..." so I can use
> it with a simple datafile[names,] query.
>
> How do I get these names in plain number formats?

Not sure what you mean by "plain number formats" but this should get  
you a vector of "names" assuming the prediction object is named  
"predobject":

names( predobject at x.values )

If you wanted them "as.numeric", then that is the name of the  
appropriate function.

-- 
David

>
> ______________________________________________
> 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