0 votes
1 view
in R Programming by (5.3k points)

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?

1 Answer

0 votes
by (25.3k points)

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]] <- 20

key_list[[3]] <- 30




[1] 10


[1] 20


[1] 30

Related questions

Welcome to Intellipaat Community. Get your technical queries answered by top developers !