开发者

in R, how to distribution data into different group

开发者 https://www.devze.com 2022-12-29 22:45 出处:网络
i have group like 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 find out 开发者_JAVA技巧how many in each groupYou can also use the hist function:

i have group like 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 find out 开发者_JAVA技巧how many in each group


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


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 
0

精彩评论

暂无评论...
验证码 换一张
取 消