I am having some issues with purrr
here. Not sure what the issue is. I have also tried using {{xval}}
and get()
, but they don't seem to work. It is probably just something silly that I've done but can't figure out.
library(tidyverse)
library(infer)
# this works --------
# from https://infer.tidymodels.org/articles/chi_squared.html
gss %>%
specify(college ~ finrela) %>%
hypothesise(null = "independence") %>%
calculate(stat = "Chisq")
# this does not!!! ----
gss_vec <- c("sex", "partyid", "income", "class", "finrela") %>%
set_names()
chi_sq_func <- function(xval){
gss %>%
specify(college ~ .data[[xval]]) %>%
hypothesise(null = "independence") %>%
calculate(stat = "Chisq")
}
map_df(.x = gss_vec,
.f = chi_sq_func(.x),
.id = "variable")
Error: The explanatory variable
[[
cannot be found in this dataframe.The explanatory variable.data
cannot be found in this dataframe.The explanatory variablexval
cannot be found in this dataframe.