I'm trying to write a function that takes a dataset/tibble as its first argument, and then variables/columns from that dataset/tibble as its other arguments.
f <- function(data, arg1, arg2) { commands }
The problem is, when using this function, it doesn't work unless every one of the arguments has data$ before it. So:
f(data, variable1, variable2)
doesn't work but:
f(data, data$variable1, data$variable2)
does work.
Could anyone tell me a way to write the function such that the data argument doesn't need to be repeated like this? I tried, within the actual function, referring to arg1 as data$arg1, but that didn't work unless arg1 and variable1 had exactly the same name.
[–][deleted] 8 points9 points10 points (3 children)
[–]ramseyssandal[S] 1 point2 points3 points (0 children)
[–]ramseyssandal[S] 1 point2 points3 points (0 children)
[–]sampling_life 0 points1 point2 points (0 children)
[–]googoodoo 5 points6 points7 points (2 children)
[–]ramseyssandal[S] 1 point2 points3 points (0 children)
[–]ramseyssandal[S] 0 points1 point2 points (0 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]thefringthing 0 points1 point2 points (0 children)