[R] no method for coercing this S4 class to a vector

Sam Steingold sds at gnu.org
Tue Nov 6 18:58:07 CET 2012


The matrix z is save()d in <http://sds.podval.org/data/z>.
It is a product of a sparse matrix and a non-sparse matrix.
I need to scale it and write to a file in the sparse format for libsvm.

platform       x86_64-pc-linux-gnu          
arch           x86_64                       
os             linux-gnu                    
system         x86_64, linux-gnu            
status                                      
major          2                            
minor          15.2                         
year           2012                         
month          10                           
day            26                           
svn rev        61015                        
language       R                            
version.string R version 2.15.2 (2012-10-26)

Package:            SparseM
Version:            0.96
Author:             Roger Koenker <rkoenker at uiuc.edu> and Pin Ng
                    <Pin.Ng at NAU.EDU>
Maintainer:         Roger Koenker <rkoenker at uiuc.edu>
Depends:            R (>= 2.4.1), methods, stats, utils
Description:        Basic linear algebra for sparse matrices
License:            GPL (>= 2)
Title:              Sparse Linear Algebra
URL:                http://www.econ.uiuc.edu/~roger/research/sparse/sparse.html
Packaged:           2012-03-18 19:39:05 UTC; root
Repository:         CRAN
Date/Publication:   2012-03-18 20:55:08
Built:              R 2.15.2; x86_64-pc-linux-gnu; 2012-11-05 17:46:36
                    UTC; unix



> * Sam Steingold <fqf at tah.bet> [2012-11-05 12:40:25 -0500]:
>
> all of a sudden, after a SparseM upgrade(?)
> I get this error:
>> str(z)
> Formal class 'matrix.csr' [package "SparseM"] with 4 slots
>   ..@ ra       : num [1:85372672] -0.4288 0.0397 0.0104 -0.1843 -0.1203 ...
>   ..@ ja       : int [1:85372672] 1 2 3 4 5 6 7 8 9 10 ...
>   ..@ ia       : int [1:699777] 1 123 245 367 489 611 733 855 977 1099 ...
>   ..@ dimension: int [1:2] 699776 122
>> z1<-as.matrix(z)
> Error in as.vector(data) : 
>   no method for coercing this S4 class to a vector
>> z1<-scale(z)
> Error in as.vector(data) : 
>   no method for coercing this S4 class to a vector
>
> what has happened?
> how do I scale the matrix.csr object (to be written to a file)?
>
> PS. write.matrix.csr is very slow: it takes
>     user   system  elapsed
> 1137.058  510.615 1649.925
> to write the matrix "z" above.
>
> thanks!

-- 
Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000
http://www.childpsy.net/ http://openvotingconsortium.org
http://www.memritv.org http://iris.org.il http://pmw.org.il
He who laughs last thinks slowest.




More information about the R-help mailing list