Skip to content

Post: creating indicator variables in a dplyr chain #35

@tgerke

Description

@tgerke

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions