R: Extract columns of a dataframe through string matching

Viewed 3938

I have a dataframe where the variables are character-strings. How can I extract only those columns where at least one value matches a particular string? For example, in the dataframe below, I want a match of the string "AB", i.e. I want to subset out another dataframe containing the columns V1, V2 and V5.

V1      V2      V3      V4      V5
ABCD    ABEF    EFGJ    AFASD   JLKJLXKJ
LKJAF   ROGIJ   GREJWI  SDFS    ABKLJKJX
AFSD    JLASDF  JKLJ    OIJPOI  AFSD
3 Answers
Related