I have an understanding problem with passing arguments to a function in R.
In the following example, I retrieve a value from a named list by name. When I do it directly, it returns the value. But when I put the same code into a function, it returns NULL. What happens here?
Thanks in advance, Mirko
namedlist <- list(a=c("50", "80"), b=c("50"))
namedlist$a
# returns: [1] "50" "80"
myfunction <- function(arg){ namedlist$arg }
myfunction(a)
# returns: NULL
See Question&Answers more detail:os