I have a simple question, but I can't figure out a simple solution:
library(data.table)
plouf <- data.table(1:10,letters[1:10])
plouf[V1 %in% c(3,1),V2]
[1] "a" "c"
I would like the output to keep the initial order of the subsetting vector, i.e. "c" "a"
. What are the possiblities ?
I have
sapply(c(3,1),function(x){plouf[V1 == x,V2]})
but I find it uggly.
edit
I have
setkey(plouf,V1)
plouf[c(3,1),V2]
which is surely the good way for data.table. Still I am curious about what are the solutions