在R中,Cut为范围1到9和0.1到0.9产生不等的间隔

问题描述 投票:0回答:1

在以下示例中,

@为什么数字1到9的间隔被切割为0,3,6,9, @尽管两种情况下的表示类似,但0.1到0.9的数字间隔被切割为0.1,0.2,0.6和0.9 @?为什么? ---见输出

 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 )
      )

输出:

  [,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
r intervals cut
1个回答
0
投票

@问题概述了[这里] [1],谢谢@Joran。 @我发现这项工作围绕不等切割间隔的解决方案。 @我在R中使用了圆函数。通过将选项设置为2位,没有解决问题。

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 ))
)

基于选项(数字= 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 ))
)

基于圆函数的等切割间隔输出:

      [,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
© www.soinside.com 2019 - 2024. All rights reserved.