Skip to content
Prev 260131 / 398502 Next

Summarize by two or more attributes

Like This?

x<-rep(c(1,15),10)
y<-rnorm(20)
z<-c(rep("auto",10),rep("bus",10))
a<-rep(c(1,1,2,2,3,3,4,4,5,5),2)
#Create Data frame
Df<-data.frame(Source=x,Rate=y,Bin=a,Type=z)
Df

ddply(Df,c('Type','Bin'),summarise,Summed=sum(Rate))

?# Adding a column to Df
ddply(Df,c('Type','Bin'),mutate,Summed=sum(Rate))
? 
# Convert the result to a list
dlply(Df,c('Type','Bin'),summarise,Summed=sum(Rate))


?
Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish & Wildlife Service
California, USA
http://www.fws.gov/redbluff/rbdd_jsmp.aspx




----- Original Message ----