【发布时间】:2020-10-02 08:36:49
【问题描述】:
我正在尝试删除数据表中的连续值。因此,在这种情况下,如果a 列中有超过 2 个零,我想消除每个变量的所有行。所以我需要像maxgap 这样的东西来定义允许多少连续零以实现一定的灵活性。
这是一个例子:
library(data.table)
dt <- data.table(a = c(1, 2, 1, 0, 0, 0, 0, 1, 2),
b = as.factor(c("x", "y", "x", "x", "y", "z", "x", "y", "y")),
c = c(2, 5, 1, 0, 3, 6, 0, 3, 4))
结果如下:
dtRes <- data.table(a = c(1, 2, 1, 1, 2),
b = as.factor(c("x", "y", "x", "y", "y")),
c = c(2, 5, 1, 3, 4))
【问题讨论】:
标签: r data.table na