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

Copenhagen: Simplification of code with if_any, Part II #23

Open
JoaodcPires opened this issue Jan 31, 2023 · 0 comments
Open

Copenhagen: Simplification of code with if_any, Part II #23

JoaodcPires opened this issue Jan 31, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@JoaodcPires
Copy link
Collaborator

Similar to the previous issue:

# Start with the linelist:
linelist <- linelist %>% 
  
  # Create ate_anything column:
  mutate(ate_anything = case_when(
    
    # ate_anything = FALSE if none of the exposure columns are TRUE:
    if_all(.cols = all_of(exposure_cols), 
           .fns = ~ !. %in% c(TRUE)) ~ FALSE,
    
    # ate_anything = TRUE if any of the exposure columns are TRUE:
    if_any(.cols = any_of(exposure_cols), 
           .fns = ~ . == TRUE) ~ TRUE
    
  ))

Alternative

# Start with the linelist:
linelist <- linelist %>% 
  
  # Create ate_anything column:
  mutate(ate_anything = case_when(
    
    # ate_anything = TRUE if any of the exposure columns are TRUE:
    if_any(.cols = any_of(exposure_cols), 
           .fns = ~ . == TRUE) ~ TRUE,
    
    TRUE ~ FALSE
    
  ))
@JoaodcPires JoaodcPires added the enhancement New feature or request label Jan 31, 2023
@JoaodcPires JoaodcPires changed the title Simplification of code with if_any, Part II Copenhagen: Simplification of code with if_any, Part II Jan 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant