我正在运行最新的data.table版本:
> packageVersion("data.table")
#[1] ‘1.11.4’
让我们考虑这个例子:
df <- data.frame(id = c(rep(1,5),rep(2,4)) ,subgrp = rep(letters[1:3],each=3),value = 1:9,stringsAsFactors = FALSE)
result<-
setDT(df)[,.(first_subgrp = subgrp[1],
sum_val = sum(value)),by="id"][,gt_15 := ifelse(sum_val > 15, T, F)]
result #nothing happens
result
版本略有不同,但行为相同。
df <- data.frame(id = c(rep(1,5),rep(2,4)) ,subgrp = rep(letters[1:3],each=3),value = 1:9,stringsAsFactors = FALSE)
result<-
as.data.table(df)[,.(first_subgrp = subgrp[1],
sum_val = sum(value)),by="id"][,gt_15 := ifelse(sum_val > 15, T, F)]
result #nothing happens again.
result
问题:为什么data.table df
仅打印在第二个“呼叫”上。