I have data frame like this :
df <- data.frame(col1 = c(letters[1:4],\"a\"),col2 = 1:5,col3 = letters[10:14])
df
col1 col2 col3
1 a 1 j
2 b
Something like this?
which(apply(df, 2, function(x) any(grepl("a", x))))
The steps are:
apply go over each columna is in this column with greplany to get TRUE if any element has been matched to awhich elements (columns) are TRUE (i.e. contain the searched letter a).