3

I have data frame in following format

Question                Year
filter with question?   2010
keep this row           2009
keep this row too       2008
remove this one?        2007

expected results

Question                Year
keep this row           2009
keep this row too       2008

Get the subset of data frame excluding column Question contains question mark '?'.

1 Answer 1

2

We can use grep to filter out the ? elements in 'Question' column

df1[!grepl('\\?', df1$Question),]
#           Question Year
#2     keep this row 2009
#3 keep this row too 2008
Sign up to request clarification or add additional context in comments.

2 Comments

Cool. Works fine! Thanks. I am kind of beginner on r and most of the help online I found was how to get subset easily for numerical filter.
@Mutant No problem. In cases where you need to find a pattern in a string, grep works fine.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.