[R] reshaping the data

Jim Lemon drjimlemon at gmail.com
Mon Jul 3 11:38:49 CEST 2017


Hi Bogdan,
If you want something like this:

             22M     17M     11M
AEBP1  SNV     SNV     NA
ATR       INDEL   NA       NA
ATR       SNV     NA        NA
BTK        NA       NA      SNV
BTK       NA       NA       INDEL

You're in trouble with repeated row names. Same with column names if
you add extra columns for repeated values. You'll have to change
something in order to make this consistent.

Jim

On Mon, Jul 3, 2017 at 5:22 PM, Bogdan Tanasa <tanasa at gmail.com> wrote:
> Dear all,
>
> I would appreciate please a piece of help regarding the use of acast/dcast
> functions in reshape2 package.
>
> Specifically, I'm working with a data frame, that has information about
> SAMPLE, GENE, and TYPE of MUTATION (as shown below):
>
> Sample    Gene  Type
> 22M       AEBP1   SNV
> 17M       AEBP1   SNV
> 22M         ATR   INDEL
> 22M         ATR   SNV
> 11M         BTK   SNV
> 11M         BTK INDEL
>
>
> I would like to transform this DATAFRAME into a MATRIX that has GENE on
> ROWS, SAMPLE on COLUMNS, and the elements of the matrix are SNV or INDEL
> (ie the types of mutations).
>
> The R code starts with :
>
> y <- data.frame(Sample = x$Sample, Gene = x$Gene, Type=x$Type)
>
> z <- acast(y, Cancer_Gene ~ Sample)
>
> although in z, I do not have the information on Type (i.e.SNV or INDEL).
>
> thanks a lot,
>
> -- bogdan
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list