Jake
Jake

Reputation: 4670

r: converting matrix.csr to matrix. Error in as.vector(data)

This is a quick question and answer as I wasted about an hour on this error

I was trying to convert a sprse matrix to a regular matrix before running a PCA.

rawm1=read.matrix.csr(".\\rjsmall1.libsvm")
str(rawm1)
sparse=rawm1$x
str(sparse)
sparseMatrix=as.matrix(sparse)

I got the following error

Error in as.vector(data) : no method for coercing this S4 class to a vector

Upvotes: 0

Views: 224

Answers (1)

Jake
Jake

Reputation: 4670

The answer is that you need to use library library(SparseM).

as.matrix 

is a standard r function, but it doesn't convert matrix.csr. The function in SparseM does.

Upvotes: 0

Related Questions