Vlad Skvortsov
2007-Nov-15 06:57 UTC
[R] what is the "right" way to obtain frequencies of vector values?
Hi! Let's say I have vector x with positive integer values ranging from 1 to N. I need to obtain another vector y of size N where y[i] contains the number of times value i occurs in x. It is in a sense similar to hist() (with appropriate number of breaks) or table() with numeric "factors". Currenlty I use a custom function for that, but thought maybe there is a more "direct" way in R. Thanks! -- Vlad Skvortsov, vss at 73rus.com, http://vss.73rus.com
Dieter Menne
2007-Nov-15 10:09 UTC
[R] what is the "right" way to obtain frequencies of vector values?
Vlad Skvortsov <vss <at> 73rus.com> writes:> Let's say I have vector x with positive integer values ranging from 1 to > N. I need to obtain another vector y of size N where y[i] contains the > number of times value i occurs in x. It is in a sense similar to hist() > (with appropriate number of breaks) or table() with numeric "factors". > > Currenlty I use a custom function for that, but thought maybe there is a > more "direct" way in R.table works with numerics: table(c(1,1,3,4,12,123,12,2,21,2,2,2)) 1 2 3 4 12 21 123 2 4 1 1 2 1 1 Dieter