Hello all R users, I have a problems transforming (or maybe better regrouping) a data.frame. I have a big data.frame, which I would like to sum up according to a specific column. This is an example of my matrix: ID gen 0042787 gen2 0016070 gen2 0016070 gen3 0007409 Gen1 0007409 gen3 0006511 gen2 0006417 gen3 0016070 gen4 0006511 gen4 I want to rearrange the matrix according to column GO, so that it will look likes that: GO:0042787 gen2 GO:0016070 gen2 : gen3 : gen4 GO:0007409 gen1 : gen3 GO:0006511 gen2 : gen4 GO:0006417 gen3 I've tried it with the package doBy (lapplyBy and paste) but it just doesn't work out. I will be very happy for any suggestions you might have to help me. Thanks Assa [[alternative HTML version deleted]]
Like this?> library(doBy) > (ddd <- read.table("foo.txt",header=T))ID gen 1 42787 gen2 2 16070 gen2 3 16070 gen3 4 7409 Gen1 5 7409 gen3 6 6511 gen2 7 6417 gen3 8 16070 gen4 9 6511 gen4> aa<-lapplyBy(~ID, data=ddd,+ FUN=function(uu){ + list(uu$ID[1], paste(uu$gen, collapse=":")) + })> > do.call(rbind,aa)[,1] [,2] 42787 42787 "gen2" 16070 16070 "gen2:gen3:gen4" 7409 7409 "Gen1:gen3" 6511 6511 "gen2:gen4" 6417 6417 "gen3" Regards S?ren -----Oprindelig meddelelse----- Fra: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] P? vegne af Assa Yeroslaviz Sendt: 8. juli 2010 10:45 Til: r-help at stat.math.ethz.ch Emne: [R] transformation of data.frame Hello all R users, I have a problems transforming (or maybe better regrouping) a data.frame. I have a big data.frame, which I would like to sum up according to a specific column. This is an example of my matrix: ID gen 0042787 gen2 0016070 gen2 0016070 gen3 0007409 Gen1 0007409 gen3 0006511 gen2 0006417 gen3 0016070 gen4 0006511 gen4 I want to rearrange the matrix according to column GO, so that it will look likes that: GO:0042787 gen2 GO:0016070 gen2 : gen3 : gen4 GO:0007409 gen1 : gen3 GO:0006511 gen2 : gen4 GO:0006417 gen3 I've tried it with the package doBy (lapplyBy and paste) but it just doesn't work out. I will be very happy for any suggestions you might have to help me. Thanks Assa [[alternative HTML version deleted]] ______________________________________________ R-help at r-project.org mailing list 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.
Hi r-help-bounces at r-project.org napsal dne 08.07.2010 10:45:04:> Hello all R users, > > I have a problems transforming (or maybe better regrouping) adata.frame.> I have a big data.frame, which I would like to sum up according to a > specific column. > > This is an example of my matrix: > ID gen > 0042787 gen2 > 0016070 gen2 > 0016070 gen3 > 0007409 Gen1 > 0007409 gen3 > 0006511 gen2 > 0006417 gen3 > 0016070 gen4 > 0006511 gen4 > > I want to rearrange the matrix according to column GO, so that it willlook> likes that: > > GO:0042787 gen2 > GO:0016070 gen2 : gen3 : gen4 > GO:0007409 gen1 : gen3 > GO:0006511 gen2 : gen4 > GO:0006417 gen3 > > I've tried it with the package doBy (lapplyBy and paste) but it justdoesn't> work out.Perhaps aggregate(test$gen, list(test$ID), function(x) paste(x, collapse=":")) Regards Petr> > I will be very happy for any suggestions you might have to help me. > > Thanks > > Assa > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.