0

I have a table ABC with three columns,

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,

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
pogibas
  • 27,303
  • 19
  • 84
  • 117
  • 4
    Possible duplicate of [How to reshape data from long to wide format?](https://stackoverflow.com/questions/5890584/how-to-reshape-data-from-long-to-wide-format) – pogibas Jun 11 '18 at 09:20

2 Answers2

0

a simple spread will do here.

df1 <- df %>%
  spread( key = Tumor_Sample, value = Consequence, fill = NA)  
Wimpel
  • 26,031
  • 1
  • 20
  • 37
0
#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"))
Marta
  • 27
  • 7
  • Did you get this error using the original dataset of this question? Because I got this error with the cast function of the reshape package. And disappeared with the recast function of reshape2 package. – Marta Jun 12 '18 at 12:40