Delete multiple lines based on one line
In the dataframe below, I have 3 variables. id (from A1 to A10); var A to E and value. I want to delete certain lines based on these conditions.
For each variable var
(A, B, C, D, or E);
If
id == A5
uif a
value < 5
then
remove all lines (10 lines) for that particular variable.
I would be grateful for any suggestions on how to do this.
> dput(df)
structure(list(id = structure(c(1L, 3L, 4L, 5L, 6L, 7L, 8L, 9L,
10L, 2L, 1L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 2L, 1L, 3L, 4L,
5L, 6L, 7L, 8L, 9L, 10L, 2L, 1L, 3L, 4L, 5L, 6L, 7L, 8L, 9L,
10L, 2L, 1L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 2L), .Label = c("A1",
"A10", "A2", "A3", "A4", "A5", "A6", "A7", "A8", "A9"), class = "factor"),
var = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L), .Label = c("A",
"B", "C", "D", "E"), class = "factor"), value = c(2, 4, 7,
8, 8, 6, 3, 8, 4, 2, 3, 5, 4, 3, 2, 7, 4, 2, 1, 22, 54, 21,
36, 52, 14, 75, 12, 15, 24, 3, 2, 4, 5, 7, 9, 21, 22, 12,
12, 12, 0.3, 0.4, 0.9, 2, 3, 2, 0.5, 0.2, 0.4, 0.7)), .Names = c("id",
"var", "value"), class = "data.frame", row.names = c(NA, -50L
))
+3
source to share