0

Here is a sample dataframe:

Col1  Col2  Col3 
   1     0     0
   0     1     0
   1     0     0
   1     0     1
   0     1     1

I want to return the following data frame:

Col1  Col2  Col3
   1     0     1
   0     1     1

That is, I want each row with more than one instance of "1"

I am having difficulty because when using the duplicated function, it is returning the instances where there are multiple values = 0, meaning that each row from the original data frame would be included in the new data frame (not what I want)

JRP
  • 125
  • 2
  • 10
  • 2
    does `rowSums(x) > 1` do what you want? – dww Jul 17 '17 at 17:49
  • 2
    Expanding on @dww: `df[rowSums(df) > 1, ]`, where `df` is your data.frame. – George Wood Jul 17 '17 at 17:51
  • Removing duplicates would give you rows 1,2,4 and 5. What you're filtering on doesn't sound like duplication. I think the comments above are what you want. And one of you 2 commenters should make it into an official answer. – Hack-R Jul 17 '17 at 17:51
  • yes, sorry rowsums(x) > 1 works exactly how I want it – JRP Jul 17 '17 at 17:54

1 Answers1

1

We can use

df[rowSums(df) > 1, ]
dww
  • 30,425
  • 5
  • 68
  • 111