[R] Frequency vector

David Carslaw d.c.carslaw at its.leeds.ac.uk
Tue Aug 12 11:39:09 CEST 2008


how about:
a <- c(1,1,1,1,2,3,4,5,5)
b <- as.data.frame(table(a))
b
  a Freq
1 1    4
2 2    1
3 3    1
4 4    1
5 5    2

which you can then select the bits you want from.

David





dennis11 wrote:
> 
> I want to create a vecor with frequencies. 
> 
> I have tried this:
> 
> a <- c(1,1,1,1,2,3,4,5,5)
> b <- table(a)
> print (b[1])
> 
> which results in:
>> print (b[1])
> 1 
> 4 
> 
> The only thing I want is the 4.
> 
> So this seems obvious:
> print (b[1,2])
> 
> but it does not work:
> Error in b[1, 2] : incorrect number of dimensions
> 
> How do I get a vector or how do I refer to the "4" without getting the "1"
> label as well?
> 


-----
Institute for Transport Studies
University of Leeds
-- 
View this message in context: http://www.nabble.com/Frequency-vector-tp18939882p18940830.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list