在R中,当使用命名行时,是否可以将稀疏矩阵列添加(连接)到另一个稀疏矩阵? [英] In R, when using named rows, can a sparse matrix column be added (concatenated) to another sparse matrix?

查看:157
本文介绍了在R中,当使用命名行时,是否可以将稀疏矩阵列添加(连接)到另一个稀疏矩阵?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个稀疏矩阵m1m2:

> m1 <- Matrix(data=0,nrow=2, ncol=1, sparse=TRUE, dimnames=list(c("b","d"),NULL))
> m2 <- Matrix(data=0,nrow=2, ncol=1, sparse=TRUE, dimnames=list(c("a","b"),NULL))
> m1["b",1]<- 4
> m2["a",1]<- 5
> m1
2 x 1 sparse Matrix of class "dgCMatrix"

b 4
d .
> m2
2 x 1 sparse Matrix of class "dgCMatrix"

a 5
b .
>

,并且我想cbind()他们制作一个稀疏矩阵,如:

and I want to cbind() them to make a sparse matrix like:

  [,1] [,2] 
a    .    5
b    4    .
d    .    .

但是cbind()忽略命名的行:

> cbind(m1[,1],m2[,1])
  [,1] [,2]
b    4    5
d    0    0

有没有办法做到这一点而没有暴力循环?

is there some way to do this without a brute force loop?

推荐答案

您应该将问题发送给Matrix软件包的大部分作者Martin Maechler.有一个cBind函数,但是至少在我所知的范围内(即使将deparse.level参数增加到2时),此刻它也不能识别行名,只能识别尺寸.

You should send the question to Martin Maechler, the author of much of the Matrix package. There is a cBind function, but it does not at the moment recognize rownames, only dimensions, at least as far as I can tell (even when increasing the deparse.level argument to 2).

这篇关于在R中,当使用命名行时,是否可以将稀疏矩阵列添加(连接)到另一个稀疏矩阵?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆