首页 > 解决方案 > S4 对象数据提取

问题描述

我不知道这是否可能。但我认为它应该是。我非常感谢任何帮助,因为我很新。

counts 是我从我正在为微生物组分析做的在线课程中获得的一个 S4 对象。

enter code here> 

str(counts)
Formal class 'dgCMatrix' [package "Matrix"] with 6 slots
  ..@ i       : int [1:10483] 4 12 18 19 23 36 44 64 76 77 ...
  ..@ p       : int [1:156] 0 59 144 229 289 368 416 462 552 625 ...
  ..@ Dim     : int [1:2] 201 155
  ..@ Dimnames:List of 2
  .. ..$ : chr [1:201] "Methanobrevibacter_smithii" "Methanosphaera_stadtmanae" "Rothia_mucilaginosa" "Propionibacterium_freudenreichii" ...
  .. ..$ : chr [1:155] "PRISM.7122" "PRISM.7147" "PRISM.7150" "PRISM.7153" ...
  ..@ x       : num [1:10483] 0.0001 0.0099 0.0077 0.0005 0.3367 ...
  ..@ factors : list()

这是结构,您可以看到插槽的长度可变。我想要一个数据框,其中细菌名称作为我的行,在 counts@Dimnames[[1]] 和 counts@Dimnames[[2]] 作为我的列。如果我只是打印看起来像这样的计数,我可以看到 counts@x 中的值到相应的位置。

Methanobrevibacter_smithii       .      .       .      .      . .      .      .       .      .     
Methanosphaera_stadtmanae        .      .       .      .      . .      .      .       .      .     
Rothia_mucilaginosa              .      9.4e-06 .      .      . .       5e-04 1.0e-04  1e-04 .     
Propionibacterium_freudenreichii .      .       0.0018 .      . .      .      .       .      .     
Bifidobacterium_adolescentis      1e-04 .       0.0403  1e-04 .  1e-04 .      .       .       1e-04

提前致谢!

标签: s4

解决方案


推荐阅读