I want to call filter(df, col_name == value)
such as filter(mpg, hwy == 27)
, but
df <- mpg
col_name <- 'hwy'
value <- 27
col <- df[col_name]
filter(df, col == value)
yields the error
Error: Problem with filter()
input ..1
.
i Input ..1
is col == value
.
x object 'value' not found
Run rlang::last_error()
to see where the error occurred.
How can I correct col_name <- df[col_name]
so that it doesn't produce this error? I've noticed that typeof() and class() produce different results for col (list; tbl_df, tbl, data.frame) and mpg$df (int;int). How do I change col (an object of class tibble and type list) to the same type as mpg$df (int)?
rlang::last_error()
gave:
<error/dplyr_error>
Problem with filter()
input ..1
.
i Input ..1
is .data[["hwy"]] == value
.
x Column hwy
not found in .data
Backtrace:
Run rlang::last_trace()
to see the full context.