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

2011-08-18 Thread Sabrina Friedman
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

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

2011-08-18 Thread Dennis Murphy
Hi: Another possibility is x - c(2,2,3,3,4,6) tabulate(x, 8) [1] 0 2 2 1 0 1 0 0 where the second argument of tabulate() allows one to specify the number of bins, in order from 1 up to the specified value, with all others outside that range ignored. HTH, Dennis On Thu, Aug 18, 2011 at 12:29

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

2011-07-31 Thread Paul Menzel
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

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

2011-07-31 Thread Sarah Goslee
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 paulepan...@users.sourceforge.net wrote: Dear R folks, I am sorry to ask this

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

2011-07-31 Thread Jeffrey Dick
Here's an attempt using sapply: x - c(2, 2, 3, 3, 4, 6) ys - 1:8 sapply(ys, function(y) { length(which(x==y)) } ) [1] 0 2 2 1 0 1 0 0 Jeff On Sun, Jul 31, 2011 at 2:41 PM, Paul Menzel paulepan...@users.sourceforge.net wrote: Dear R folks, I am sorry to ask this simple question, but my

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

2011-07-31 Thread Dénes TÓTH
See also ?tabulate. tabulate(x,8) 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