开发者

In R How do I load a matrix market formated sparse matrix into a dgCMatrix?

开发者 https://www.devze.com 2023-02-04 11:03 出处:网络
I\'m trying to use the the Matrix package to read a MatrixMarket formatted file, but I get back a ngTMatrix. I can\'t convert it with as since there is no method for converting from ngTMatrix to dgCMa

I'm trying to use the the Matrix package to read a MatrixMarket formatted file, but I get back a ngTMatrix. I can't convert it with as since there is no method for converting from ngTMatrix to dgCMatrix. Converting it to a non-sparse matrix isn't an option as its too large. Any suggest开发者_Go百科ions?


I'm not sure why you're having a problem, because you can use as() to coerce an ngTMatrix to an ngCMatrix:

> pm <- as(as.integer(c(2,3,1)), "pMatrix")
3 x 3 sparse Matrix of class "pMatrix"

[1,] . | .
[2,] . . |
[3,] | . .

> pm.t <- as(pm, 'ngTMatrix')
> pm.c <- as(pm.t, 'ngCMatrix')

> class(pm.c)
[1] "ngCMatrix"
attr(,"package")
[1] "Matrix"

> class(pm.t)
[1] "ngTMatrix"
attr(,"package")
[1] "Matrix"
0

精彩评论

暂无评论...
验证码 换一张
取 消