我已经包含了20行数据帧:
structure(list(countyfips = c(1003, 1003, 1003, 1003, 1003, 1005,
1005, 1005, 1005, 1005, 1007, 1007, 1007, 1007, 1007, 1009, 1009,
1009, 1009, 1009), engagement = c("-.186", "-.231", "-.0681",
"-.38", "-.267", "-.0148", ".00322", ".0804", "-.478", "-.83",
"-.0532", "-.162", "-.0185", "-.883", "-.909", ".0278", "-.537",
"-.691", "-.972", "-.981")), row.names = c(NA, -20L), class = c("tbl_df",
"tbl", "data.frame"))
我使用以下表达式将其分组:
math_stu_online_engage %>%
group_by(countyfips) %>% summarise(monthly_engagement = list(engagement))
现在,我想对“每月约定”列的每个列表/行应用以下缩减功能:
mutate(acc_perc_change = Reduce(function(x, y) x + x * y, monthly_engagement))
但我有一个错误:
Error: Problem with `mutate()` input `acc_perc_change`.
x non-numeric argument to binary operator
我做错了什么?
非常感谢!