1

im having trouble removing/filtering rows based on multiple conditions.

My data looks like this:

      time              media id    od  gfp
37    0.24    IO+Glc+CasA_gfp  1  0.00   81
38    0.24    IO+Glc+CasA_gfp  2 -0.07  -19
39    0.24    IO+Glc+CasA_gfp  3  0.02  -95
43    0.24 IO+Glc+CasA+Fe_gfp  1  0.01  123
44    0.24 IO+Glc+CasA+Fe_gfp  2  0.01  -17
45    0.24 IO+Glc+CasA+Fe_gfp  3  0.02  -40
85    0.72    IO+Glc+CasA_gfp  1 -0.02  128
86    0.72    IO+Glc+CasA_gfp  2 -0.01  -20
87    0.72    IO+Glc+CasA_gfp  3  0.01  -77
91    0.72 IO+Glc+CasA+Fe_gfp  1  0.14   15
92    0.72 IO+Glc+CasA+Fe_gfp  2  0.11  -12
93    0.72 IO+Glc+CasA+Fe_gfp  3  0.02   15

When plotting a specific graph i would like to filter all "IO+Glc+CasA+Fe_gfp" with id=1 and 2, but still keep everything else in the data. I have tried to use the filtering function but without luck, most likely because im using the function incorrectly.

I hope anyone can help, thanks a lot in advance!

1 Answer 1

2
library(dplyr)
quux %>%
  filter(id %in% 1:2 | media != "IO+Glc+CasA+Fe_gfp")
#    time              media id    od gfp
# 37 0.24    IO+Glc+CasA_gfp  1  0.00  81
# 38 0.24    IO+Glc+CasA_gfp  2 -0.07 -19
# 39 0.24    IO+Glc+CasA_gfp  3  0.02 -95
# 43 0.24 IO+Glc+CasA+Fe_gfp  1  0.01 123
# 44 0.24 IO+Glc+CasA+Fe_gfp  2  0.01 -17
# 85 0.72    IO+Glc+CasA_gfp  1 -0.02 128
# 86 0.72    IO+Glc+CasA_gfp  2 -0.01 -20
# 87 0.72    IO+Glc+CasA_gfp  3  0.01 -77
# 91 0.72 IO+Glc+CasA+Fe_gfp  1  0.14  15
# 92 0.72 IO+Glc+CasA+Fe_gfp  2  0.11 -12

Rationale:

  • id %in% 1:2 will match against every media, true for only those two IDs; however
  • media != "..", will return TRUE for anything that's not "the one", so all of the non-"IO+Glc+..." IDs will be passed as well.

Data

quux <- structure(list(time = c(0.24, 0.24, 0.24, 0.24, 0.24, 0.24, 0.72, 0.72, 0.72, 0.72, 0.72, 0.72), media = c("IO+Glc+CasA_gfp", "IO+Glc+CasA_gfp", "IO+Glc+CasA_gfp", "IO+Glc+CasA+Fe_gfp", "IO+Glc+CasA+Fe_gfp", "IO+Glc+CasA+Fe_gfp", "IO+Glc+CasA_gfp", "IO+Glc+CasA_gfp", "IO+Glc+CasA_gfp", "IO+Glc+CasA+Fe_gfp", "IO+Glc+CasA+Fe_gfp", "IO+Glc+CasA+Fe_gfp"), id = c(1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L), od = c(0, -0.07, 0.02, 0.01, 0.01, 0.02, -0.02, -0.01, 0.01, 0.14, 0.11, 0.02), gfp = c(81L,  -19L, -95L, 123L, -17L, -40L, 128L, -20L, -77L, 15L, -12L, 15L)), class = "data.frame", row.names = c("37", "38", "39", "43", "44", "45", "85", "86", "87", "91", "92", "93"))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.