I have multiple objects and I need to apply some function to them, in my example mean. But the function call shouldn’t include list, it must look like this: my_function(a, b, c).
Advise how to do it please, probably I need quote or substitute, but I’m not sure how to use them.
a <- c(1:15)
b <- c(1:17)
c <- c(1:19)
my_function <- function(objects) {
lapply(objects, mean)
}
my_function(list(a, b, c))
>Solution :
A possible solution:
a <- c(1:15)
b <- c(1:17)
c <- c(1:19)
my_function <- function(...) {
lapply(list(...), mean)
}
my_function(a, b, c)
#> [[1]]
#> [1] 8
#>
#> [[2]]
#> [1] 9
#>
#> [[3]]
#> [1] 10