将多个相等尺寸矩阵与单个矩阵与每个单元格组合的单元格值是r的列表,作为r的输入矩阵的值

发布于 2025-02-03 02:15:32 字数 671 浏览 1 评论 0原文

输入: 相同维度有三个输入矩阵 3输入矩阵:

              GeneA             GeneB          
GeneA          31                  4           
GeneB           5                  8 

              GeneA             GeneB          
GeneA           5                 14           
GeneB           5                  8 


              GeneA             GeneB          
GeneA          30                 14           
GeneB           45                 7 

输出:

                GeneA             GeneB          
GeneA          {31,5,30}         {4,14,14}          
GeneB          {5,5,45}           {8,8,7} 

一个具有单元格值的矩阵作为输入矩阵值的列表。

Input:
There are three input matrices of same dimensions
3 input matrices:

              GeneA             GeneB          
GeneA          31                  4           
GeneB           5                  8 

              GeneA             GeneB          
GeneA           5                 14           
GeneB           5                  8 


              GeneA             GeneB          
GeneA          30                 14           
GeneB           45                 7 

output:

                GeneA             GeneB          
GeneA          {31,5,30}         {4,14,14}          
GeneB          {5,5,45}           {8,8,7} 

one matrix with cell value as a list of the values from the input matrices.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

天邊彩虹 2025-02-10 02:15:32

您可以使用mapply,然后将结构和dimnames分配为matrix1

matrix(
  mapply(paste, matrix1, matrix2, matrix3, MoreArgs=list(sep=",")), 
  nrow=nrow(matrix1),
  ncol=ncol(matrix1),
  dimnames = dimnames(matrix1)
)

output的dimnames:

      GeneA     GeneB    
GeneA "31,5,30" "4,14,14"
GeneB "5,5,45"  "8,8,7"  

You can use mapply, and then assign the structure and dimnames as those from matrix1

matrix(
  mapply(paste, matrix1, matrix2, matrix3, MoreArgs=list(sep=",")), 
  nrow=nrow(matrix1),
  ncol=ncol(matrix1),
  dimnames = dimnames(matrix1)
)

Output:

      GeneA     GeneB    
GeneA "31,5,30" "4,14,14"
GeneB "5,5,45"  "8,8,7"  
牛↙奶布丁 2025-02-10 02:15:32

您需要将每个结果向量保存在矩阵中的列表中。如果您的矩阵被称为M1M2m3,那么您可以做:

m <- `dimnames<-`(matrix(lapply(1:4, function(i) c(m1[i], m2[i], m3[i])), 2),
                  dimnames(m1))

以便我们有

m
#>       GeneA     GeneB    
#> GeneA integer,3 integer,3
#> GeneB integer,3 integer,3

m[1, 1]
#> [[1]]
#> [1] 31  5 30

You would need to hold each resulting vector within a list in a matrix. If your matrices are called m1, m2 and m3, then you can do:

m <- `dimnames<-`(matrix(lapply(1:4, function(i) c(m1[i], m2[i], m3[i])), 2),
                  dimnames(m1))

So that we have:

m
#>       GeneA     GeneB    
#> GeneA integer,3 integer,3
#> GeneB integer,3 integer,3

and

m[1, 1]
#> [[1]]
#> [1] 31  5 30
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文