I have two dataframes a and b.
a can be 2000-3000 rows long with 15 columns.
b is a small dataframe (2 columns with 150 rows).
Below a simplified dataset.
a <- structure(list(ID = structure(c(1L, 2L, 1L, 3L, 2L, 1L, 3L), .Label = c("ID1",
"ID2", "ID3"), class = "factor"), score = structure(c(4L, 5L,
3L, 6L, 7L, 1L, 2L), .Label = c("10", "110", "20", "28", "34",
"80", "90"), class = "factor"), desc = structure(c(1L, 1L, 1L,
1L, 1L, 1L, 1L), class = "factor", .Label = "text")), .Names = c("ID",
"score", "desc"), row.names = c(NA, -7L), class = "data.frame")
b <- structure(list(ID = structure(1:3, .Label = c("ID1", "ID2", "ID3"
), class = "factor"), cutoff = structure(1:3, .Label = c("12",
"46", "54"), class = "factor")), .Names = c("ID", "cutoff"), row.names = c(NA,
-3L), class = "data.frame")
I would like to filter dataframe a using the scores from dataframe b. For example in dataframe b the ID "ID1" has a cutoff of 12, so i only want to keep ID1 from dataframe a above or equal to 12. I would like to do this for all IDS.
> a
ID score desc
1 ID1 28 text
2 ID2 34 text
3 ID1 20 text
4 ID3 80 text
5 ID2 90 text
6 ID1 10 text
7 ID3 110 text
> b
ID cutoff
1 ID1 12
2 ID2 46
3 ID3 54
Given the cutoffs in dataframe b the final dataframe a should remain as follows:
> a
ID score desc
1 ID1 28 text
2 ID1 20 text
3 ID3 80 text
4 ID2 90 text
5 ID3 110 text