使用gather()在R中使用tidyr包;无效的列规范“;
我还在学习如何使用tidyr。我想使用“gather()”将列分成多行,并在适当的地方复制“gene_ID”列来保留它。 输入数据示例:使用gather()在R中使用tidyr包;无效的列规范“;,r,tidyr,R,Tidyr,我还在学习如何使用tidyr。我想使用“gather()”将列分成多行,并在适当的地方复制“gene_ID”列来保留它。 输入数据示例: gene_ID path1 path2 path3 path4 path5 path6 path7 path8 CAMNT_0043146643 RNA transport CAMNT_0029561721 Ribosome
gene_ID path1 path2 path3 path4 path5 path6 path7 path8
CAMNT_0043146643 RNA transport
CAMNT_0029561721 Ribosome
CAMNT_0024703307 Sphingolipid signaling pathway Lysosome
CAMNT_0020981363 mRNA surveillance pathway Hippo signaling pathway cAMP signaling pathway cGMP - PKG signaling pathway Regulation of actin cytoskeleton Meiosis - yeast Oocyte meiosis Focal adhesion
CAMNT_0020021387 Spliceosome Protein processing in endoplasmic reticulum MAPK signaling pathway Endocytosis
CAMNT_0003293445 Spliceosome Protein processing in endoplasmic reticulum MAPK signaling pathway Endocytosis
所需输出数据的示例:
gene_ID Pathway
CAMNT_0043146643 RNA transport
CAMNT_0029561721 Ribosome
CAMNT_0024703307 Lysosome
CAMNT_0024703307 Sphingolipid signaling pathway
CAMNT_0020981363 mRNA surveillance pathway
CAMNT_0020981363 Hippo signaling pathway
CAMNT_0020981363 cAMP signaling pathway
CAMNT_0020981363 cGMP - PKG signaling pathway
CAMNT_0020981363 Regulation of actin cytoskeleton
CAMNT_0020981363 Meiosis - yeast
CAMNT_0020981363 Oocyte meiosis
CAMNT_0020981363 Focal adhesion
CAMNT_0020021387 Spliceosome
CAMNT_0020021387 Protein processing in endoplasmic reticulum
CAMNT_0020021387 MAPK signaling pathway
CAMNT_0020021387 Endocytosis
CAMNT_0003293445 Spliceosome
CAMNT_0003293445 Protein processing in endoplasmic reticulum
CAMNT_0003293445 MAPK signaling pathway
CAMNT_0003293445 Endocytosis
目前,我正在尝试:
temp<-gather(extract,"gene_ID",path1:path8)
tempdf这里有一个tidyr
解决方案:
df %>%
gather(path, Pathway, path1, path2) %>%
filter(Pathway != "") %>%
select(-path)
x Pathway
1 a test1
2 b test1
3 c test2
4 d test2
5 e test3
6 a testa
7 c testg
8 d testd
我们无法使用您的数据集,而且它看起来不像是标准的df。下面是一个更好的示例:输入:df,然后是所需的输出:out
df %>%
gather(path, Pathway, path1, path2) %>%
filter(Pathway != "") %>%
select(-path)
x Pathway
1 a test1
2 b test1
3 c test2
4 d test2
5 e test3
6 a testa
7 c testg
8 d testd