Cut Function: Making Irregular cuts in R

后端 未结 1 958
刺人心
刺人心 2021-01-28 23:41

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 t

1条回答
  •  自闭症患者
    2021-01-29 00:00

    ?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
    

    0 讨论(0)
提交回复
热议问题