'R get elements from a list using another list of indices

I have a list of keywords. To access a keyword on this list I type keyword$Keyword[1]. I have another list, called abc, of indices. If I look at the list I see:

[[1]]
[1] 1303496

[[2]]
[1] 2345

which are indices from the elements in the keyword list.

How do I use the elements from the abc list to list out the keywords?

I'm thinking I would use which, but which is for a vector and these are lists.

Thanks

r


Solution 1:[1]

If I've understood well, you got something like this:

keyword <- list('a','b','c','d')
index <- list(1,3)

Now let's think you need the keywords with index 1 and 3 in index:

keyword[unlist(index)]

[[1]]
[1] "a"

[[2]]
[1] "c"

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 s__