Back
I have a trivial question: I couldn't find a dictionary data structure in R, so I used a list instead (like "word"->number) So, right now I have a problem how to get the list of keys. Does anybody know?
You can use the names() function on your list to set and retrieve keys for the elements.
For example:
key_list <- vector(mode="list", length=3)names(key_list) <- c("key1", "key2", "key3")key_list[[1]] <- 10 key_list[[2]] <- 20key_list[[3]] <- 30key_list
key_list <- vector(mode="list", length=3)
names(key_list) <- c("key1", "key2", "key3")
key_list[[1]] <- 10
key_list[[2]] <- 20
key_list[[3]] <- 30
key_list
Output:
$key1[1] 10$key2[1] 20$key3[1] 30
$key1
[1] 10
$key2
[1] 20
$key3
[1] 30
31k questions
32.8k answers
501 comments
693 users