Is it possible to assign subtraction (or division) in R as object and to call it? So that following example produce -1
a <- 1
b <- 2
method <- "-"
a method b
# Wanted result -1
method <- "/"
a method b
# Wanted result 0.5
Why I need this
I want to set function parameter to either -
or /
. Something like that:
dummyF <- function(a, b, method) {
a get(method) b
}