Skip to content

Instantly share code, notes, and snippets.

@shv38339
Created April 18, 2017 16:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shv38339/17866b135f620c9ee61c7c70c4ba9e5d to your computer and use it in GitHub Desktop.
Save shv38339/17866b135f620c9ee61c7c70c4ba9e5d to your computer and use it in GitHub Desktop.
Combine list names with list levels in order to imitate the coefficient output from summary(lm(...)) objects in R (aka smushed variable names with variable levels)
# place list levels in object
list_levels <-
mtcars %>% select(vs, gear) %>%
transmute(vs_fctr = factor(vs, labels = c("0. Zero", "1. One")),
gear_fctr = factor(gear, labels = c("3. Three", "4. Four", "5. Five"))) %>%
sapply(levels) # sapply extracts unique levels from all variables
# i still don't understand this code but it works...
lapply(seq_along(list_levels),
function(i) paste(names(list_levels)[[i]], list_levels[[i]], sep = "")) %>%
unlist()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment