0

I have quite a large dataset. I would like to exclude people who have certain conditions.

In other words, I want to drop rows that have answered yes to the question.

How do I do that?

Thank you very much.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Tess
  • 67
  • 6
  • 2
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Sep 09 '20 at 03:41

2 Answers2

-1

We can use rowSums on a logical matrix. If the whole dataset includes columns with 'yes', 'no' values, convert the dataset to a logical matrix df1 == 'yes', get the rowSums, check if it is equal to 0 i.e. the row doesn't haven't any 'yes', use that to subset the rows

df1[rowSums(df1 == 'yes', na.rm = TRUE) == 0,]

If it is a single column, use subset

 subset(df1, col1 == "yes")
akrun
  • 874,273
  • 37
  • 540
  • 662
-1

I have done it using data.table pakage in R,

If you have a data with the column "yes" and "no" and wanted to remove those rows with "yes", you can try this

df <- data.table(A=seq(1:5),B=c("yes","yes","no","no","no"))
df
A   B
1: 1 yes
2: 2 yes
3: 3  no
4: 4  no
5: 5  no
df[!B=="yes",]
A  B
1: 3 no
2: 4 no
3: 5 no

Hope it will serve your purpose.

Gourab
  • 54
  • 3