Paul Christoph Schröder
2007-Oct-25 17:21 UTC
[R] Find duplicates and save their max value
Hi, maybe someone can help me with this: I have a matrix of genes and values: GeneName Value Abc1 10 Abc2 11 Bbc1 -5 Bbc31 2 Ccd 5 Ccd -2 Ccd 7 Dda 5 Dda 10 ..... ..... Zzz3 -1 I would like to create a new matrix where the GeneNames which are duplicated and do not have the absolut maximum value between these duplicated genes, are deleted; i.e. GeneName Value Abc1 10 Abc2 11 Bbc1 -5 Bbc31 2 Ccd 7 Dda 10 ..... ..... Zzz3 -1 Does anyone know if there is a function that works this way in R? How would you do it? Thank you very much in advance! Cheers Paul [[alternative HTML version deleted]]
Hi, data.frame(GeneName=unique(df$GeneName),Value=sapply(unique(df$GeneName), function(x)max(df$Value[df$GeneName==x]))) On 25/10/2007, Paul Christoph Schröder <pschrode@alumni.unav.es> wrote:> > Hi, > > maybe someone can help me with this: > > I have a matrix of genes and values: > GeneName Value > Abc1 10 > Abc2 11 > Bbc1 -5 > Bbc31 2 > Ccd 5 > Ccd -2 > Ccd 7 > Dda 5 > Dda 10 > ..... ..... > Zzz3 -1 > > I would like to create a new matrix where the GeneNames which are > duplicated and do not have the absolut maximum value between these > duplicated genes, are deleted; i.e. > > GeneName Value > Abc1 10 > Abc2 11 > Bbc1 -5 > Bbc31 2 > Ccd 7 > Dda 10 > ..... ..... > Zzz3 -1 > > Does anyone know if there is a function that works this way in R? How > would you do it? > Thank you very much in advance! > > Cheers > > Paul > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@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. >-- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]
?aggregate b On Oct 25, 2007, at 1:21 PM, Paul Christoph Schr?der wrote:> Hi, > > maybe someone can help me with this: > > I have a matrix of genes and values: > GeneName Value > Abc1 10 > Abc2 11 > Bbc1 -5 > Bbc31 2 > Ccd 5 > Ccd -2 > Ccd 7 > Dda 5 > Dda 10 > ..... ..... > Zzz3 -1 > > I would like to create a new matrix where the GeneNames which are > duplicated and do not have the absolut maximum value between these > duplicated genes, are deleted; i.e. > > GeneName Value > Abc1 10 > Abc2 11 > Bbc1 -5 > Bbc31 2 > Ccd 7 > Dda 10 > ..... ..... > Zzz3 -1 > > Does anyone know if there is a function that works this way in R? How > would you do it? > Thank you very much in advance! > > Cheers > > Paul > > > [[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.