How can I subset the following dataset based on the fact that Numeric_variable includes 2 for some units (e.g. A), and 3 for some other units (e.g. B)?
Unit | Numeric_variable
A | 1
A | 1
A | 2
A | 2
A | 2
A | 2
C | 1
C | 1
C | 2
C | 2
C | 2
C | 2
B | 1
B | 1
B | 3
B | 3
B | 3
B | 3
D | 1
D | 1
D | 3
D | 3
D | 3
D | 3
Into:
df1:
Unit | Numeric_variable
A | 1
A | 1
A | 2
A | 2
A | 2
A | 2
C | 1
C | 1
C | 2
C | 2
C | 2
C | 2
df2:
Unit | Numeric_variable
B | 1
B | 1
B | 3
B | 3
B | 3
B | 3
D | 1
D | 1
D | 3
D | 3
D | 3
D | 3
By doing df1 <- df[which(df$Numeric_variable != 3),], I obtain the below which is not what I would like to get. I would like to get the above df1.
Unit | Numeric_variable
A | 1
A | 1
A | 2
A | 2
A | 2
A | 2
B | 1
B | 1
D | 1
D | 1