更新时间:2022-06-21 22:57:33
我们可以使用group by选项,然后执行 sample
p>
We can use group by option and then do sample
dt[, NextItem := sample(x, 1), by = Name]
或者您也可以使用 .N
而不是 / code>
Or you can also do this with .N
instead of by
dt[, NextItem := sample(x, .N, replace = TRUE)]