Re: [R] bind mean to a df

2011-04-11 Thread baptiste auguie
Hi, You could try, library(plyr) ddply(data, .(name), transform, mean=mean(sale)) ddply(data, .(name), summarize, mean=mean(sale)) HTH, baptiste On 12 April 2011 15:46, Geoffrey Smith wrote: > Hello, I would like to take the mean of a column from a data frame and then > bind the mean back to

Re: [R] bind mean to a df

2011-04-11 Thread Joshua Wiley
Hi Geoffrey, Here is one option (data named dfrm instead of data because data() is a function too): ## Data dfrm <- data.frame( name = c('Frank','Frank','Frank','Tony','Tony','Tony','Ed','Ed','Ed'), year = c(2004,2005,2006,2004,2005,2006,2004,2005,2006), sale = c(56,45,55,65,68,70,45,67,23)

[R] bind mean to a df

2011-04-11 Thread Geoffrey Smith
Hello, I would like to take the mean of a column from a data frame and then bind the mean back to the data frame. I can do this using the following lines of code, but I am looking for a more elegant solution. Thank you very much. Geoff name <- c('Frank','Frank','Frank','Tony','Tony','Tony','Ed'