Skip to content
Prev 279298 / 398503 Next

Group several variables and apply a function to the group

Aur?lien PHILIPPOT wrote
One way would be to use the aggregate function. 

# Your Data ... 
# Note:  I have removed the quotes off the output variable x
comn<-c("abc", "abc", "abc", "abc", "abc", "abc", "xyz", "xyz","xyz", "xyz")
mi<- c("1", "1","1", "2", "2", "2", "1", "1", "3", "3")
x<- c(-0.0031, 0.0009, -0.007, 0.1929,0.0087, 0.099,-0.089, 0.005, -0.0078,
0.67)
df<- data.frame(comn=comn, mi=mi, x=x)

# Aggregate Function
aggregate(df$x, by=list(df$comn,df$mi),FUN=sd)

HTH

Pete

--
View this message in context: http://r.789695.n4.nabble.com/Group-several-variables-and-apply-a-function-to-the-group-tp4158017p4158090.html
Sent from the R help mailing list archive at Nabble.com.