[R] putting stuff into bins...

Dietrich Trenkler Dietrich.Trenkler at uni-osnabrueck.de
Tue Sep 26 14:00:09 CEST 2006


Federico Calboli schrieb:
> Hi All,
>
> I have a vector of data, a vector of bin breakpoints and I want to put my data 
> in the bins and then extract fanciful informations like the mean value of each bin.
>
> I know I can write my own function, but I would have thought that R should have 
> somewhere a function that took as arguments something like (data, breaks, what 
> to do with the data in the bins). I surey could not find it trawling the R-help 
> archives though.
>
> If such a function exists I'd be grateful to anyone pointing it out to me.
>
> Cheers,
>
> Fede
>
>   
The following should be of help:

"bd384" <- c(2.968, 2.097, 1.611, 3.038, 7.921, 5.476, 9.858,
    1.397, 0.155, 1.301, 9.054, 1.958, 4.058, 3.918, 2.019, 3.689,
    3.081, 4.229, 4.669, 2.274, 1.971, 10.379, 3.391, 2.093,
    6.053, 4.196, 2.788, 4.511, 7.3, 5.856, 0.86, 2.093, 0.703,
    1.182, 4.114, 2.075, 2.834, 3.698, 6.48, 2.36, 5.249, 5.1,
    4.131, 0.02, 1.071, 4.455, 3.676, 2.666, 5.457, 1.046, 1.908,
    3.064, 5.392, 8.393, 0.916, 9.665, 5.564, 3.599, 2.723, 2.87,
    1.582, 5.453, 4.091, 3.716, 6.156, 2.039)
cut(bd384,0:11)
split(bd384,cut(bd384,0:11))
sapply(split(bd384,cut(bd384,0:11)),mean)

D.Trenkler


-- 
Dietrich Trenkler c/o Universitaet Osnabrueck 
Rolandstr. 8; D-49069 Osnabrueck, Germany    
email: Dietrich.Trenkler at Uni-Osnabrueck.de



More information about the R-help mailing list