I am trying to pass a column name through the bi_class
function within my broader create_sf_func()
function to use to create tertile cutoffs for bivariate maps in R. I am using the following code, but cannot figure out how to get R to recognize my variable
argument of my function as a variable in the dataframe. Any help would be greatly appreciated.
create_sf_func <- function(yrqrt, variable) {
df <- bi_class(df2, x = QRT_TESTS_PER1K, y = df2[[variable]], style = "quantile", dim = 3)
df_filtered <- sf::st_as_sf(df %>% filter(YEAR_QRT == yrqrt) %>%
right_join(all_fips, by=c("FIPS5"="FIPS5")) %>%
mutate(geometry = fips_geometry(FIPS5)) %>% filter(FIPS5<60), crs = 4269) %>%
shift_geometry()
# Filter the data frame by year using the filter function
# df_filtered <- filter(df, year == year)
# Return the filtered data frame
return(df_filtered)
}
df_cases2022Q2 <- create_sf_func("2022Q2", "CASES_PER100K")
This is the error I am getting:
Error in if (var %in% names(.data) == FALSE) { :
the condition has length > 1