Suppose I have this named vector in R:
foo=vector()
foo['a']=1
foo['b']=2
foo['c']=3
How is it most pure to make another named vector with elements 'a' and 'c' only?
If it was a data frame with a column "name" and a column "value", I could use
subset(df, name %in% c('a', 'b'))
which is good, because a subset can evaluate any logical expression, therefore it is quite flexible.
source
share