Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 用三角帆把大桌子聚合起来_R_Tidyverse - Fatal编程技术网

R 用三角帆把大桌子聚合起来

R 用三角帆把大桌子聚合起来,r,tidyverse,R,Tidyverse,我有以下数据表: library(tidyverse) df <- data.frame(READS=rep(c('READa', 'READb', 'READc'),each=3) ,GENE=rep(c('GENEa', 'GENEb', 'GENEc'), each=3), COMMENT=rep(c('CommentA', 'CommentA', 'CommentA'),each=3)) > df READS GENE COMMENT 1 READa GENEa

我有以下数据表:

library(tidyverse)

df <- data.frame(READS=rep(c('READa', 'READb', 'READc'),each=3) ,GENE=rep(c('GENEa', 'GENEb', 'GENEc'), each=3), COMMENT=rep(c('CommentA', 'CommentA', 'CommentA'),each=3))

> df
  READS  GENE  COMMENT
1 READa GENEa CommentA
2 READa GENEa CommentA
3 READa GENEa CommentA
4 READb GENEb CommentA
5 READb GENEb CommentA
6 READb GENEb CommentA
7 READc GENEc CommentA
8 READc GENEc CommentA
9 READc GENEc CommentA

您能否以长格式保存摘要输出,即
df%>%count(READS,GENE)
好奇的是,为什么您需要从理想的长格式重新调整为宽格式?矩阵赋值如何:?受@Aaron启发。我希望能够将长格式导出为更易于阅读的格式。虽然我可能会重新考虑,看看是否可以过滤掉一些数据。这是一个800个样本的实验,可以解释如此大的数据。有没有任何情况下,你可以在多次读取中获得一个基因的计数?
df %>%
  count(READS, GENE) %>%
  pivot_wider(
    names_from = GENE, values_from = n,
    values_fill = list(n = 0)
  )

  A tibble: 3 x 4
   READS GENEa GENEb GENEc
   <chr> <int> <int> <int>
 1 READa     3     0     0
 2 READb     0     3     0
 3 READc     0     0     3
Error: Can´t index beyond the end of a vector.
The vector has length 1 and you´ve tried to submit element 712.