Working with dictionaries/lists in R: how to get the values from the key-value pairs?
问题 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