This is related to Working with dictionaries/lists in R, where we try to create a key-value style dictionary with vectors, but now about how to access the values.
I can get the keys in the following way
foo <- c(12, 22, 33)
names(foo) <- c("tic", "tac", "toe")
names(foo)
[1] "tic" "tac" "toe"
and I can access the elements
> lapply(FUN=function(a){foo[[a]]},X = 1:length(foo))
[[1]]
[1] 12
[[2]]
[1] 22
[[3]]
[1] 33
and then I can do
unlist(lapply(FUN=function(a){foo[[a]]},X = 1:length(foo)))
[1] 12 22 33
#or
sapply(FUN=function(a){foo[[a]]},X = 1:length(foo))
[1] 12 22 33
but this is very inconvenient. How can I conveniently access the values in the format c(12,22,33)
? Is there some ready convenient command for this in R?