0
$\begingroup$

I am trying to filter a data frame where I need to search for a regular expression within the data frame.

dim(df)
[1] 10299 561

I wanted to know if there is a way, I could find the name(s) of the column(s) where a particular regex may be available.

As an example, how do I find the name of the column where 'rsi' is present. I am referring to iris.

$\endgroup$
1
  • $\begingroup$ By the way, I think there have been a lot of questions of this kind over at StackOverflow.com. $\endgroup$
    – maj
    Aug 24, 2015 at 16:58

1 Answer 1

2
$\begingroup$

Would this work for you,

 names(iris)[apply(iris, 2, function(x) any(grepl("rsi", x)))]
$\endgroup$
1
  • $\begingroup$ Works perfectly! I should have been able to think of that. Thanks for this simple and elegant solution. $\endgroup$
    – Drj
    Aug 24, 2015 at 20:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.