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.
You can try this, which is similar to @ColonelBeauvel
identical(as.vector(unlist(l1[v])), c("A", "C"))
[1] TRUE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With