Dear all,
Lets say I have the following data frame:
set.seed(1)
col1 - c(rep('happy',9), rep('sad', 9))
col2 - rep(c(rep('alpha', 3), rep('beta', 3), rep('gamma', 3)),2)
dates - as.Date(rep(c('2009-10-13', '2009-10-14', '2009-10-15'),6))
score=rnorm(18, 10, 3)
df1-data.frame(col1=col1,
aves = aggregate(df1$score, by=list(col1=df1$col1, col2=df1$col2), mean)
results = merge(df1, aves)
b
On Oct 21, 2009, at 9:03 AM, Tony Breyal wrote:
Dear all,
Lets say I have the following data frame:
set.seed(1)
col1 - c(rep('happy',9), rep('sad', 9))
col2 - rep(c(rep('alpha', 3),
On 10/21/2009 7:03 AM, Tony Breyal wrote:
Dear all,
Lets say I have the following data frame:
set.seed(1)
col1 - c(rep('happy',9), rep('sad', 9))
col2 - rep(c(rep('alpha', 3), rep('beta', 3), rep('gamma', 3)),2)
dates - as.Date(rep(c('2009-10-13', '2009-10-14', '2009-10-15'),6))
In article 800acfc0-2c3c-41f1-af18-3b52f7e43...@jhsph.edu,
bcarv...@jhsph.edu says...
aves = aggregate(df1$score, by=list(col1=df1$col1, col2=df1$col2), mean)
results = merge(df1, aves)
Or, with the 'plyr' package, which has a very nice syntax:
library(plyr)
ddply(df1, .(col1, col2),
Thank you all for your responses, i have now achieved the desired
output for my own real data using your suggestions. I will also have
to look into this 'plyr' package as i have noticed that it gets
mentioned a lot.
On 21 Oct, 13:33, Karl Ove Hufthammer k...@huftis.org wrote:
In article
5 matches
Mail list logo