[R] Which hist cell each value falls in?
Doug Hill
logickledoug at yahoo.com
Thu Dec 17 20:35:44 CET 2009
Hi, all. I'm using hist() to obtain a vector of break values in an interval.
I then want to be able to identify which cell any value from another vector
falls in.
E.g. applying
> breaks
[1] -3.5 -3.0 -2.5 -2.0 -1.5 -1.0 -0.5 0.0 0.5 1.0 1.5 2.0
to
> x
[1] -3.74519666 -0.38183630 -1.22884247 -0.20971824 -0.30533939 -0.36271207
[7] -2.27513499 -2.23688653 -1.98827155 -1.48666274 -1.26155084 -0.15234555
[13] -0.09497287 0.34488440
would give
> xcells
[1] 1 8 6 8 8 8 4 4 5 6 6 8 8 9
where:
x <= breaks[1] -> cell 1
breaks[1] < x <= breaks[2] -> cell 2
breaks[2] < x <= breaks[3] -> cell 3, etc.
I'm sure there's either a built-in function or a concise way to do this, but
I've not figured it out.
Thanks,
Doug
--
View this message in context: http://n4.nabble.com/Which-hist-cell-each-value-falls-in-tp974316p974316.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list