[R] table function
Marc Schwartz
marc_schwartz at me.com
Mon Aug 24 18:33:52 CEST 2009
On Aug 24, 2009, at 10:59 AM, Inchallah Yarab wrote:
> hi,
>
> i want to use the function table to build a table not of frequence
> (number of time the vareable is repeated in a list or a data
> frame!!) but in function of classes
> I don t find a clear explnation in examples of ?table !!!
>
> example
>
> x y z
> 1 0 100
> 5 1 1500
> 6 1 1200
> 2 2 500
> 1 1 3500
> 5 2 2000
> 8 5 4500
>
> i want to do a table summerizing the number of variable where z is
> in [0-1000],],[1000-3000], [> 3000]
>
> thank you very much for your help
See ?cut, which bins a continuous variable.
> DF
x y z
1 1 0 100
2 5 1 1500
3 6 1 1200
4 2 2 500
5 1 1 3500
6 5 2 2000
7 8 5 4500
> table(cut(DF$z, breaks = c(-Inf, 1000, 3000, Inf),
labels = c("0 - 1000", ">1000 - 3000", ">3000")))
0 - 1000 >1000 - 3000 >3000
2 3 2
HTH,
Marc Schwartz
More information about the R-help
mailing list