[英]Create a table from multiple columns of another table
I have a table ABC with three columns, 我有一个三列的表格ABC,
Hugo_Symbol Consequence Tumor_Sample
AACS missense_variant WCMC10362_2_C
AADACL4 missense_variant WCMC188_1_C
AADACL4 missense_variant WCMC189_1_C
AADACL4 missense_variant WCMC10362_2_C
AASS splice_variant WCMC10362_2_C
ABCA13 missense_variant WCMC188_1_C
ABCA13 missense_variant WCMC10362_2_C
I need to create a new table df1 with the values from the three columns of ABC, 我需要使用ABC的三列中的值创建一个新表df1,
Hugo_Symbol WCMC188_1_C WCMC189_1_C WCMC10362_2_C
AACS NA NA missense_variant
AADACL4 missense_variant missense_variant missense_variant
AASS NA NA splice_variant
ABCA13 missense_variant NA missense_variant
I did not find a code that allows me to do this. 我没有找到可以执行此操作的代码。 I can create a structure of the second table as follows if there is a code to enter values into the table. 如果有代码在表中输入值,则可以按如下方式创建第二个表的结构。
Hugo_Symbol WCMC188_1_C WCMC189_1_C WCMC10362_2_C
AACS
AADACL4
AASS
ABCA13
a simple spread will do here. 一个简单的传播将在这里做。
df1 <- df %>%
spread( key = Tumor_Sample, value = Consequence, fill = NA)
#You can try with reshape package and the function recast.
library(reshape2)
recast(df1, df1$Hugo_Symbol + variable ~ df1$Tumor_Sample, id.var =
c("Hugo_Symbol", "Tumor_Sample"))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.