[R] function to include factors in summary data frame

Daniel Malter daniel at umd.edu
Mon Sep 12 22:31:10 CEST 2011

I have read it three times and still no concrete idea what you are actually
trying to do, mainly because there is no information as to which
level/variable you are aggregating on. It'd help if you provided the
aggregated data (or sample rows thereof) so that we know what you want the
result to be.


Wade Wall wrote:
> Hi all,
> I have a dataframe that includes data on individuals that are distributed
> across multiple rows.  I have aggregated the data using ddply, but I have
> columns in the original data frame that are factors ( such as sites "A",
> "B", and "C") that I would like to include in the new data frame.  I have
> done this in a clunky way using match() and a loop, but am wondering if
> there is a more elegant approach.  Here is an example data set.
> #Example
> a<-c(rep(1:5,6)); b<-sort(b)
> b<-c(rep("A",10),rep("B",10),rep("C",10))
> a<-c(rep(1:5,6)); b<-sort(b)
> d<-c(2008,2008,2009,2009,2010,2010);d<-rep(d,5)
> e<-rnorm(30,2,1)
> df<-data.frame(a,b,d,e) ; names(df)<-c("ind","site","year","height")
> I created a new factor using ind and year, and would basically like to
> include site in the new dataframe. Does anyone know how this could easily
> be
> done?
> Thanks in advance.
> 	[[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.

View this message in context: http://r.789695.n4.nabble.com/function-to-include-factors-in-summary-data-frame-tp3808391p3808538.html
Sent from the R help mailing list archive at Nabble.com.

More information about the R-help mailing list