I have a data frame 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 |
(in fact, this material appeared as a result of another message , but this is not very important, because this is a separate issue)
I'm just looking for a way to apply df with bool values to "regular" df and get the following:
| x | y |
|---|---|
| | e |
| | f |
| c | |
| d | |
This question asked a very similar question, but the solutions diverged in different directions.
I have tried many different indexing schemes, but all of them do not preserve the rectangular structure of the result that I want.
df[mask] was too good to be true.
Any advice is greatly appreciated.
My details:
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")