Cut Function: Making Irregular cuts in R

走远了吗. 提交于 2020-05-09 17:12:56

问题


I need to use the cut function to divide into irregular, uneven breaks.

I need to cut into ranges such as 1 to 15, 16 to 19, 20 to 45... ect. Though I do not know how to do this or if it is possible. Please help!


回答1:


?cut is a good first step...

Here is a sample from which you can build:

# create a long vector that you want to cut
z <- rnorm(10000)
# create a vector with irregular breakpoints
breaks <- c( -6, -1, 1, 3, 6 )
# cut the long vector, look at the `table()`d result
table( cut( z, breaks ) )
  (-6,-1]  (-1,1]   (1,3]   (3,6] 
     1572    6806    1608      14


来源:https://stackoverflow.com/questions/33542885/cut-function-making-irregular-cuts-in-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!