[R] FW: How to count numbers of a vector and use them as index values?
Freeh Sophia
freehsophia at gmail.com
Thu Aug 25 13:34:38 CEST 2011
Hi Paul,
I would use something like this:
> x <- c(2,2,3,3,4,6)
> table(x)
x
2 3 4 6
2 2 1 1
> x <- factor(x, levels=1:8)
> table(x)
x
1 2 3 4 5 6 7 8
0 2 2 1 0 1 0 0
Sarah
On Sun, Jul 31, 2011 at 5:41 PM, Paul Menzel
<paulepanter at users.sourceforge.net> wrote:
> 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
>
--
Sarah Goslee
http://www.functionaldiversity.org
Freeh Sophia
Marketing GmbH
Emanuelstr. 3,
10317 Berlin
Deutschland
Telefon: +49 (33) 5310967
Email: freehsophia at gmail.com
Site: http://flug.airego.de/
More information about the R-help
mailing list