DC and TWPL in r studio help

Hi Everyone,

I've been doing the empirical project 11.4. this is my code:

variables <- list(quo(sex), quo(age),
                  quo(kids_nr), quo(hhnetinc),
                  quo(member), quo(education))

for (i in seq_along(variables)){
  WTP %>%
    group_by(abst_format, !!variables[[i]]) %>%
    summarize (n = n()) %>%
    mutate(freq = n / sum(n)) %>%
    select(-n) %>%
    spread(abst_format, freq) %>%
    print()
}


But i got this error while i run my code: 

>   WTP %>%
+     group_by(abst_format, !!variables[[i]]) %>%
+     summarize (n = n()) %>%
+     mutate(freq = n / sum(n)) %>%
+     select(-n) %>%
+     spread(abst_format, freq) %>%
+     print()
`summarise()` regrouping output by 'abst_format' (override with `.groups` argument)
Error in spread(., abst_format, freq) : could not find function "spread"

Thank You, 

Anastasia

spread() is from the tidyr package, you have to load it first.

If you need more specific help, please provide a proper REPRoducible EXample (reprex) illustrating your issue.

Got it! Thank you so much!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.