I want to map variable to a number as shown in the list below through a function.
x <- list(
a = 1,
b = 2,
c = 3
)
x$a
[1] 1
I need to use this mapping at different places inside a script so I want to use a function that returns the number if I pass in the variable. However, if I make a function as shown below it does not work. Not sure what I am missing.
get_x <- function(var) {
x <- list(
a = 1,
b = 2,
c = 3
)
return(x$var)
}
get_x(a)
NULL
Coming form python background so this seems a logical way to do it.