As an example, I created a data like this
df<- structure(list(Names = c("AA", "ab", "CC", "AVY"), Column1 = c(0L,
0L, 0L, 1L), Column2 = c(0L, 0L, 0L, 0L), Column3 = c(0L, 0L,
0L, 1L)), class = "data.frame", row.names = c(NA, -4L))
I want to subset and keep those rows that have my strings in them lets say 3 of them if I want to find the position, I can using the following to find where CC is
which(df=="CC", arr.ind=TRUE)
or if I want to find two of them CC and ab , I can
which(df==c("CC","ab"), arr.ind=TRUE)
but what I want is to subset it in a new data frame like below
Name Column1 Column2 Column3
ab 0 0 0
CC 0 0 0
I found for one string at the time based on other people solutions but still if I have more than one I dont know how to do it
df[sapply(df, function(x) grepl("CC",x)),]