Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
4 views
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
edited by

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

key_list

Output:

$key1

[1] 10

$key2

[1] 20

$key3

[1] 30

Related questions

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...