[R] Reshape a sparse matrix

Scott Hyde hydes at byuh.edu
Wed May 16 05:03:13 CEST 2007


I'd like to reshape a sparse matrix generated from the Matrix package.  I can't seem to do it with the command

dim(A) <- c(6,9)

which works perfectly with the base package matrices, but with the sparse matrices it errors with

Error in dim(A) = c(6, 9) : dim<- : invalid first argument

Manipulating the Dim attribute of the sparse Matrix does not produce the desired effect. A at Dim <- c(as.integer(9),as.integer(6)) does not produce a column ordering result, which I am assuming is because the data is stored in a row (i) and column (j) format instead (class dgTMatrix)

Does a function for this exist?


More information about the R-help mailing list