Re: [R] putting stuff into bins...

From: Dietrich Trenkler <Dietrich.Trenkler_at_uni-osnabrueck.de>
Date: Tue 26 Sep 2006 - 12:00:09 GMT

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@Uni-Osnabrueck.de

______________________________________________
R-help@stat.math.ethz.ch 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.
Received on Tue Sep 26 22:03:41 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 26 Sep 2006 - 12:30:06 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.