In R, how to distribute data to different groups

i have a group of type 1-10, 10-20, 20-30, 30-40. and I have data like "1,23,24,11,33,22,5,6,7,8,3,2", how can I know how many are in each group

+2


a source to share


2 answers


You can also use the hist function:



y <- c(1,23,24,11,33,22,5,6,7,8,3,2)
h <- hist(y, seq(0, 40, 10), plot=0) # plot=0 avoids plotting the histogram
# Refer to h$counts to get the counts in each bin

      

+7


a source


R> table(cut(c(1,23,24,11,33,22,5,6,7,8,3,2), 
             breaks=seq(0, 40, by=10), right=FALSE))

 [0,10) [10,20) [20,30) [30,40) 
      7       1       3       1 

      



+2


a source







All Articles