I have a dataframe as such:
| x | y |
|---|---|
| a | e |
| b | f |
| c | g |
| d | h |
and I have a dataframe of bool values as such:
| x | y |
|-------|-------|
| FALSE | TRUE |
| FALSE | TRUE |
| TRUE | FALSE |
| TRUE | FALSE |
(actually this stuff came out as a result from a different post, but that's not really relevant cos this is a stand-alone question)
I'm just searching for a way to apply the df with the bool values to the 'regular' df, and get this:
| x | y |
|---|---|
| | e |
| | f |
| c | |
| d | |
This question asked a very similar question, but the solutions diverged into different directions.
I have tried a wide variety of different indexing schemes, but they all fail to retain the rectangular structure of the output that I desire.
df[mask]
was too good to be true as well.
Any advice much appreciated.
My data:
df <- data.frame(
x = c('a', 'b', 'c', 'd'),
y = c('e', 'f', 'g', 'h'), stringsAsFactors = F
)
mask <- structure(list(x = c(FALSE, FALSE, TRUE, TRUE), y = c(TRUE, TRUE,
FALSE, FALSE)), .Names = c("x", "y"), row.names = c(NA, -4L), class = "data.frame")