0

In the following Example,

@ why the interval of the numbers 1 to 9 is cut at 0, 3, 6, 9,
@ while the interval of the numbers 0.1 to 0.9 is cut at 0.1, 0.2, 0.6 and 0.9 @ even if the declarion in both situation is analogous? why?
--- see output

 cbind(
      seq(      from = 1, to = 9, by = 1 ), 
      cut( seq( from = 1, to = 9, by = 1),         breaks = c( 0, 3, 6, 9 ),   include.lowest = TRUE ),
      seq(      from = 0.1, to = 0.9, by = 0.1 ), 
      cut( seq( from = 0.1, to = 0.9, by = 0.1),   breaks = c( 0, 0.3, 0.6, 0.9 ),   include.lowest = TRUE ),
      seq(      from = 0.01, to = 0.09, by = 0.01 ), 
      cut( seq( from = 0.01, to = 0.09, by = 0.01),   breaks = c( 0, 0.03, 0.06, 0.09 ),   include.lowest = TRUE )
      )

The output:

  [,1] [,2] [,3] [,4] [,5] [,6]
 [1,]    1    1  0.1    1 0.01    1
 [2,]    2    1  0.2    1 0.02    1
 [3,]    3    1  0.3    2 0.03    1
 [4,]    4    2  0.4    2 0.04    2
 [5,]    5    2  0.5    2 0.05    2
 [6,]    6    2  0.6    2 0.06    3
 [7,]    7    3  0.7    3 0.07    3
 [8,]    8    3  0.8    3 0.08    3
 [9,]    9    3  0.9    3 0.09    3
Estatistics
  • 874
  • 9
  • 24
  • 5
    Almost certainly because of [this](https://stackoverflow.com/q/9508518/324364). – joran Feb 22 '19 at 15:59
  • @joran, So, in that case, what is the work around solution? Is there any? If we treat these numbers, as characters - factors, can we then define, exact cut points? – Estatistics Feb 22 '19 at 16:31
  • One approach would be to create the groups for the simple case (integers, maybe) and then just copy the groups over. – joran Feb 22 '19 at 16:33
  • I find another solution, by using round e.g. round(x, digits =2). – Estatistics Feb 22 '19 at 16:37
  • Do you think it is eligible to post it in the link you gave as a work around solution? – Estatistics Feb 22 '19 at 16:38
  • 1
    I think your situation is fairly specific, I wouldn't put a workaround to this particular instance on that other question. – joran Feb 22 '19 at 16:49
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/188905/discussion-between-elias-estatisticseu-and-joran). – Estatistics Feb 22 '19 at 16:54

1 Answers1

0

@ The problem was outlined [here][1], thanks @Joran. @ I found this work around solution about unequal cut intervals. @ I used the round function in R. By setting the option to 2 digits, did not solved the problem.

options(digits = 2)
cbind(
  seq(      from = 1, to = 9, by = 1 ), 
  cut( seq( from = 1, to = 9, by = 1),          c( 0, 3, 6, 9 ) ),
  seq(      from = 0.1, to = 0.9, by = 0.1 ), 
  cut( seq( from = 0.1, to = 0.9, by = 0.1),    c( 0, 0.3, 0.6, 0.9 )),
  seq(      from = 0.01, to = 0.09, by = 0.01 ), 
  cut( seq( from = 0.01, to = 0.09, by = 0.01),    c( 0, 0.03, 0.06, 0.09 ))
)

output of unequal cut intervals based on options(digits = 2):

  [,1] [,2] [,3] [,4] [,5] [,6]
 [1,]    1    1  0.1    1 0.01    1
 [2,]    2    1  0.2    1 0.02    1
 [3,]    3    1  0.3    2 0.03    1
 [4,]    4    2  0.4    2 0.04    2
 [5,]    5    2  0.5    2 0.05    2
 [6,]    6    2  0.6    2 0.06    3
 [7,]    7    3  0.7    3 0.07    3
 [8,]    8    3  0.8    3 0.08    3
 [9,]    9    3  0.9    3 0.09    3


options(digits = 200)
cbind(
  seq(      from = 1, to = 9, by = 1 ), 
  cut( round(seq( from = 1, to = 9, by = 1), 2),          c( 0, 3, 6, 9 ) ),
  seq(      from = 0.1, to = 0.9, by = 0.1 ), 
  cut( round(seq( from = 0.1, to = 0.9, by = 0.1), 2),    c( 0, 0.3, 0.6, 0.9 )),
  seq(      from = 0.01, to = 0.09, by = 0.01 ), 
  cut( round(seq( from = 0.01, to = 0.09, by = 0.01), 2),    c( 0, 0.03, 0.06, 0.09 ))
)

output of equal cut intervals based on round function:

      [,1] [,2] [,3] [,4] [,5] [,6]
 [1,]    1    1  0.1    1 0.01    1
 [2,]    2    1  0.2    1 0.02    1
 [3,]    3    1  0.3    1 0.03    1
 [4,]    4    2  0.4    2 0.04    2
 [5,]    5    2  0.5    2 0.05    2
 [6,]    6    2  0.6    2 0.06    2
 [7,]    7    3  0.7    3 0.07    3
 [8,]    8    3  0.8    3 0.08    3
 [9,]    9    3  0.9    3 0.09    3
Estatistics
  • 874
  • 9
  • 24