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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…