I want to create a function to sum two columns together, in which one word connects two columns and there are three sets. I want to pass that word as the only argument, and add a new column with that same name. Something like this.
the_first_x <- c(0,0,10,0)
the_second_x <- c(10,0,10,0)
the_first_y <- c(0,5,5,5)
the_second_y <- c(5,5,0,0)
df <- data.frame(the_first_x,
the_second_x,
the_first_y,
the_second_y)
summing <- function(letter){
df$letter <- the_first_letter + the_second_letter
}
Such that using the following adds a column with that letter as a name and that sum as its rows
summing(x)
summing(y)
By doing it like this, the letter
argument is not recognised, and using something like paste()
makes that the argument is surrounded by parentheses and also not recognised.