Daren Tan
2008-Jun-10 15:37 UTC
[R] Fast method to compute average values of duplicated IDs
Hi, How do I collapse (average in the simplest case) the values of those duplicated ids (i.e., 2, 5, 6, 9) to give a table of unique ids ? t <- cbind(id=c(1:10, 2,5,6,9), value=rnorm(14)) _________________________________________________________________ [[alternative HTML version deleted]]
Greg Snow
2008-Jun-10 16:18 UTC
[R] Fast method to compute average values of duplicated IDs
?tapply ?aggregate -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org (801) 408-8111> -----Original Message----- > From: r-help-bounces at r-project.org > [mailto:r-help-bounces at r-project.org] On Behalf Of Daren Tan > Sent: Tuesday, June 10, 2008 9:37 AM > To: r-help at r-project.org > Subject: [R] Fast method to compute average values of duplicated IDs > > > Hi, > > How do I collapse (average in the simplest case) the values > of those duplicated ids (i.e., 2, 5, 6, 9) to give a table of > unique ids ? > > t <- cbind(id=c(1:10, 2,5,6,9), value=rnorm(14)) > > > > _________________________________________________________________ > > > [[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. >
Jorge Ivan Velez
2008-Jun-10 16:34 UTC
[R] Fast method to compute average values of duplicated IDs
Dear Daren, Try this: tapply(t[,"value"],t[,"id"],mean) HTH, Jorge On Tue, Jun 10, 2008 at 11:37 AM, Daren Tan <daren76@hotmail.com> wrote:> > Hi, > > How do I collapse (average in the simplest case) the values of those > duplicated ids (i.e., 2, 5, 6, 9) to give a table of unique ids ? > > t <- cbind(id=c(1:10, 2,5,6,9), value=rnorm(14)) > > > > _________________________________________________________________ > > > [[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. >[[alternative HTML version deleted]]
Reasonably Related Threads
- Identifying common prefixes from a vector of words, and delete those prefixes
- Very slow: using double apply and cor.test to compute correlation p.values for 2 matrices
- Any simple way to subset a vector of strings that do contain a particular substring ?
- counting number of "G" in "TCGGGGGACAATCGGTAACCCGTCT"
- grouping values