I have a data frame from which I want to select a column. For that purpose I have defined a function. The name of the column is provided as parameter:
d <- data.frame(x = 1:10, y = sample(1:100, 10, replace = TRUE))
f1 <- function(data, name)
{
data[name]
}
f1(d, "x")
f1(d, "y")
However, instead of providing the column name as character string I would like to provide the column as symbol as in this form:
f2(d, x)
f2(d, y)
My question: How is f2 to be defined?
Background: This is a simplified example. Actually the function to be defined has this prototype:
fx(d, v, ...)
and returns a data frame which sums upv over any column listed in ....
aggregatewhith parameterby=<...>und functionsum.