[R] How to count numbers of a vector and use them as index values?

Paul Menzel paulepanter at users.sourceforge.net
Sun Jul 31 23:41:29 CEST 2011


Dear R folks,


I am sorry to ask this simple question, but my search for the right
way/command was unsuccessful.

I have a vector

> x <- c(2, 2, 3, 3, 4, 6)

Now the values of x should be considered the index of another vector
with possible greater length, say 8, and the value should be how often
the indexes appeared in the original vector x.

> length(result)
 [1] 8
> result
 [1] 0 2 2 1 0 1 0 0


Thank you in advance,

Paul
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110731/347cca14/attachment.bin>


More information about the R-help mailing list