[R] Counting Frequencies

Jim Lemon jim at bitwrit.com.au
Thu Dec 10 06:54:34 CET 2009


On 12/10/2009 10:36 AM, BIGBEEF wrote:
> Hi - I'm having difficulty with frequencies in R. I have a table with a
> variable (column) called "difference" 600 observations (rows). I would like
> to know how many values are<  -0.5 as well as how many are>  0.5. The rest
> are obviously in the middle.
>
> In SAS I could this immediately but am unable to do it in R.
>    
Hi Martin,

difference<-runif(100)*2-1
table(cut(difference,
  breaks=c(min(difference)-0.1,-0.5,0.5,max(difference))))

The "-0.1" is to ensure that the lowest value is included in the cut.

Jim




More information about the R-help mailing list