I am currently summarising a data set by collapsing data based on common identifiers in a column. I am using the 'aggregate' function to summarise numeric columns, i.e. "aggregate(dat[,3], list(dat$gene), mean)". I also wish to summarise text columns e.g. by concatenating values in a comma separated list, but the aggregate function can only return scalar values and so something like "aggregate(dat[,3], list(dat$gene), cat)" will not work. Is there a simple function like aggregate that works for strings in R? -------------------------------------------------------------------------- AstraZeneca UK Limited is a company incorporated in Engl...{{dropped:21}}
Hi r-help-bounces at r-project.org napsal dne 28.07.2009 17:34:35:> I am currently summarising a data set by collapsing data based on common> identifiers in a column. I am using the 'aggregate' function tosummarise> numeric columns, i.e. "aggregate(dat[,3], list(dat$gene), mean)". Ialso wish> to summarise text columns e.g. by concatenating values in a commaseparated> list, but the aggregate function can only return scalar values and so > something like "aggregate(dat[,3], list(dat$gene), cat)" will not work.Is> there a simple function like aggregate that works for strings in R?Try aggregate(dat[,3], list(dat$gene), paste, collapse=",") Regards Petr> >--------------------------------------------------------------------------> AstraZeneca UK Limited is a company incorporated inEngl...{{dropped:21}}> > ______________________________________________ > 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.
You are probably going to get tons of answers, as there are many ways -- and packages -- to do this (e.g. see packages reshape and plyr). However, you might want to take a look at ?tapply, for which aggregate() is a wrapper, for the basic core R approach. Bert Gunter Genentech Nonclinical Biostatistics -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Dry, Jonathan R Sent: Tuesday, July 28, 2009 8:35 AM To: r-help at r-project.org Subject: [R] aggregating strings I am currently summarising a data set by collapsing data based on common identifiers in a column. I am using the 'aggregate' function to summarise numeric columns, i.e. "aggregate(dat[,3], list(dat$gene), mean)". I also wish to summarise text columns e.g. by concatenating values in a comma separated list, but the aggregate function can only return scalar values and so something like "aggregate(dat[,3], list(dat$gene), cat)" will not work. Is there a simple function like aggregate that works for strings in R? -------------------------------------------------------------------------- AstraZeneca UK Limited is a company incorporated in Engl...{{dropped:8}}