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]]
Have considered "cut" and "table" ? On Dec 20, 2012 12:08 PM, "Katherine Gobin" <katherine_gobin@yahoo.com> wrote:> 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@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. > >[[alternative HTML version deleted]]
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.