I have a data frame constructed similarly to this:
df <-
read.table(textConnection("ID Column1 Column2
A 1 0
A 0 1
B 1 0
B 0 0
C 1 0
D 1 0
D 0 1"), header=TRUE)
| ID | Column1 | Column2 |
|---|---|---|
| A | 1 | 0 |
| A | 0 | 1 |
| B | 1 | 0 |
| B | 0 | 0 |
| C | 1 | 0 |
| C | 0 | 0 |
| D | 1 | 0 |
| D | 0 | 1 |
I am looking to filter the data frame so that rows are kept only when there is a value of '1' in Column1 and also a value of '1' in Column2.
So output in this case would be
| ID | Column1 | Column2 |
|---|---|---|
| A | 1 | 0 |
| A | 0 | 1 |
| D | 1 | 0 |
| D | 0 | 1 |
Any help will be very much appreciated, thank you!