Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Post: creating indicator variables in a dplyr chain #35

Open
tgerke opened this issue Nov 22, 2019 · 0 comments
Open

Post: creating indicator variables in a dplyr chain #35

tgerke opened this issue Nov 22, 2019 · 0 comments

Comments

@tgerke
Copy link
Member

tgerke commented Nov 22, 2019

With good renaming along the way. Like so (which needs a little tidying for readability):

dat <- dat %>%
  bind_cols(model.matrix(~ 0 + .$gleasoncat) %>% as_tibble() %>% select(-1)) %>%
  rename_at(vars(starts_with(".$")), ~ str_replace(., ".\\$gleasoncat", "Gleason "))

Note also the dropping of the intercept column from model.matrix and the redundant baseline column (which would cause identifiability problems in models) via select(-1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant