Skip to content
Prev 255951 / 398506 Next

Odp: Calculated mean value based on another column bin from dataframe.

Hi


r-help-bounces at r-project.org napsal dne 06.04.2011 10:48:04:
Do you want something like that?

#make data
x<-runif(100) 
y<-runif(100)

#cut first column to bins (in your case dat[,1] and ran)
x.c<-cut(x, seq(0,1,.1))

#aggregate column 2 according to bins (in your case dat[,2])
aggregate(y,list(x.c), mean)
     Group.1         x
1    (0,0.1] 0.5868734
2  (0.1,0.2] 0.5436263
3  (0.2,0.3] 0.5099366
4  (0.3,0.4] 0.4815855
5  (0.4,0.5] 0.4137687
6  (0.5,0.6] 0.4698156
7  (0.6,0.7] 0.4687639
8  (0.7,0.8] 0.5661048
9  (0.8,0.9] 0.5489297
10   (0.9,1] 0.4812521

Regards
Petr
"data.frame")
http://www.R-project.org/posting-guide.html