In R, I am trying to turn the code below into a function (with a parameter variable instead of gender).
res_gender <- payments %>%
group_by(yrmon,gender) %>%
summarise_at(vars(nbpol,nbtrans,member_revenue,untenm,untem),
list(name = sum))
write.table(res_gender, file="gender.csv",sep=",",row.names=F)
Here is my attempt (for the 1st part) and the error I get:
resum <- function(grpvar) {
res_grpvar <- payments %>%
group_by(yrmon,grpvar) %>%
summarise_at(vars(nbpol,nbtrans,member_revenue,untenm,untem),
list(name = sum))
}
resum(gender)
Error: Column grpvar is unknown
even if I give a dummy name to the output table w/o variable in its name.
Questions:
- how to write the 'resum' function in order get the exact same result as in the initial code?
- I have no clue how to write the part for the export (with datafile parametered), any suggestion?
Thanks in advance, merci!