使用 cut Error in if (d2 == 0L) { 设置 bin 分组时出错:需要 TRUE/FALSE 的地方缺少值

Error in setting bin grouping using cut Error in if (d2 == 0L) { : missing value where TRUE/FALSE needed

我尝试使用 cut 函数将我的数据集分组到不同的 bin 大小,

cuts <- apply(rd, 4, cut, c(-Inf, seq(10, 80, 10), Inf), labels=10:90)

但是弹出这个错误:

Error in if (d2 == 0L) { : missing value where TRUE/FALSE needed

我猜是因为我的某些值刚好与截止值相匹配,谁能教我如何修改我的代码,以便在匹配时将进入组 >= 值??

如果我们在第 4 列使用 cut

cut(rd[,4], breaks= c(-Inf, seq(10, 80, 10), Inf), labels=10:90)

apply 方法用于大于一维的矩阵。在这里,我们只使用第 4 列,所以函数可以直接应用于 vector.