[R] Grep out columns using a list of strings

Kate Ignatius kate.ignatius at gmail.com
Fri May 8 21:50:14 CEST 2015


Hi,

I have a list of 150 strings, say, ap,:

aajkss
dfghjk
sdfghk
...
xxcvvn


And I would l like to grep out these strings from column names in
another file, af,.   I've tried the following but none seem to work:

aps <- af[,grep(ap, colnames(af), value=TRUE)]
aps <- af[,grep(ap, colnames(af), value=FIXED)]
aps <- af[,grep(as.character(list(ap),colnames(af))]

and also aps <- unique (grep(ap, colnames(af))

Is there another way I can do this - maybe without using grep?

Thanks!

Kate.



More information about the R-help mailing list