I have a data frame with an ID column and several columns for the values. I would like to save only certain rows of the data frame based on whether the ID value in this row matches a different set of values (for example, called "hold").
For simplicity, an example is given:
df <- data.frame(ID = sample(rep(letters, each=3)), value = rnorm(n=26*3)) keep <- c("a", "d", "r", "x")
How to create a new data frame consisting of lines that have only identifiers corresponding to keep files? I can only do this for one letter using the which() function, but with a few letters I get warning messages and incorrect returns. I know that I can run a for loop through a data frame and extrapolate this path, but I wonder if there is a more elegant and efficient way around this. Thanks in advance.
source share