【发布时间】:2021-08-25 19:41:05
【问题描述】:
考虑这个data.table
library(data.table)
dt1 <- data.table(id = c("01","01","01","01","01", "02","02","02",",02","02"),
change_total = c(.00,.90,-.10,.8,.3,.00,.90,-.10,.8,.3))
如何计算每个 ID 的行之间的变化是否大于 change_total 的 25% (change_greater_than_25_percent),然后如果这些“是”大于每个 ID 的行的 25%。
看起来像这样
dt2 <- data.table(id = c("01","01","01","01", "01","02","02","02","02","02"),
change_total = c(.00,.90,-.10,.8,.3,.00,.90,-.10,.8,.3),
change_greater_than_25_percent = c("no","yes","no","no","no","no","yes","no","no","no"),
change_greater_than_25_percent_greaterthan_25_percent_ofthe_time_by_id = c("no","yes","yes","yes","no","no","yes","yes","yes","no"))
【问题讨论】:
-
那些预期的输出是否正确?我尝试了“change_greater_than_25_percent”,但根据您的输入给出了不同的输出
标签: r data.table