[R] How to count the nos. in a range?

arun smartpink111 at yahoo.com
Thu Dec 20 18:25:58 CET 2012


Hi,
Try this:
range1<-cut(x,breaks=c(0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1),labels=paste("(",c("0-0.1","0.1-0.2","0.2-0.3","0.3-0.4","0.4-0.5","0.5-0.6","0.6-0.7","0.7-0.8","0.8-0.9","0.9-1"),")",sep=""))
table(range1)
#range1
 # (0-0.1) (0.1-0.2) (0.2-0.3) (0.3-0.4) (0.4-0.5) (0.5-0.6) (0.6-0.7) (0.7-0.8) 
   #     8        13         6        18        13         8        10         9 
#(0.8-0.9)   (0.9-1) 
  #      8         7 
A.K.




----- Original Message -----
From: Katherine Gobin <katherine_gobin at yahoo.com>
To: r-help at r-project.org
Cc: 
Sent: Thursday, December 20, 2012 10:37 AM
Subject: [R] How to count the nos. in a range?

Dear R forum


I have a following vector of random no.s

x = runif(100, 0.01, 0.99)


 [1] 0.47212037 0.77867992 0.33947474 0.93369035
  [5] 0.03720073 0.79307831 0.81801835 0.92710688
.................................................


I need to count the random no. falling in the range (0 - 0.10), (0.10 - 0.20), (0.20 - 0.30)..upto (0.90 - 1) 


Thus, I
need to have a data frame as

range                   
frequency
0 - 0.10                  .......
0.10 - 0.20            
.......
......................................


0.90 - 1                 .........

I understand I need to write my code and ask for some help if the need be. But I am simply clueless at the moment.

Kindly guide.

Katherine
  
    [[alternative HTML version deleted]]


______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.





More information about the R-help mailing list