I've included 20 rows of my dataframe:
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"))
which I've grouped using the following expression:
math_stu_online_engage %>%
group_by(countyfips) %>% summarise(monthly_engagement = list(engagement))
I would now like to apply the following Reduce function to each list / row of the monthly engagement column:
mutate(acc_perc_change = Reduce(function(x, y) x + x * y, monthly_engagement))
But I'm getting this error:
Error: Problem with `mutate()` input `acc_perc_change`.
x non-numeric argument to binary operator
What am I doing wrong here?
Thanks so much!