Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R fastest way to get values from list as vector [duplicate]

Tags:

dictionary

r

in R, give a list

l1 <- list(a = "A", b = "B", c = "C")

and a vector

v<- c("a", "c")

How to get elements from the list in vector? For example

l1[v] 

returns a list, while I need a vector as

c("A", "C")

Looking for fastest one-liner.

like image 917
d.putto Avatar asked Apr 01 '15 12:04

d.putto


1 Answers

You can try this, which is similar to @ColonelBeauvel

identical(as.vector(unlist(l1[v])), c("A", "C"))
[1] TRUE
like image 93
Mamoun Benghezal Avatar answered Nov 15 '22 04:11

Mamoun Benghezal