I am trying to learn how to use base R to filter a data frame to select rows where a certain column match a specific value, BUT for a case where the filter column and the filter value are held in variables.
So for example:
df <- data.frame(id = seq(1, 100, 1), value = floor(runif(100, 0, 10))) filter_col <- "value" filter_value <- 10 # how to filter using now only filter_col and filter_value? #I tried things like this but could not get it to work: df2 <- val <- subset(df, eval(filter_col) & eval(parse(text = filter_value)))
Any help appreciated!