See ?ave (in package stats)
/hans
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
On Behalf Of Michael Pearmain
Sent: den 2 oktober 2008 15:28
To: r-help at r-project.org
Subject: [R] Help with aggregation
Hi All,
I seem to be having a few troubles with aggregating data back onto the the
dataframe,
I want to take the max value of a user, and then apply this max value back
against all id's that match (i.e a one to many matching)
Can anyone offer any advice? is there a better way of doing this?
Dummy data and code are listed below:-
dataset is called Mcookie
user_id c_we_conversion
1 1
1 0
1 0
2 1
2 1
3 0
3 0
new data
user_id c_we_conversion c_we_conversion
1 1 1
1 0 1
1 0 1
2 1 1
2 1 1
3 0 0
3 0 0
library(Hmisc)
myAgg<-summarize(Mcookie$c_we_conversion, by=Mcookie$user_id, FUN=max,
na.rm=TRUE)
names(myAgg)<- c("user_id","c_we_converter")
Mcookie <- merge(Mcookie, myAgg, by.x = "user_id", by.y =
"user_id")
Thanks in advance,
Mike
[[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.