Skip to content

Instantly share code, notes, and snippets.

@grayskripko
Last active July 19, 2019 18:58
Show Gist options
  • Save grayskripko/c94a2ef0c1853205cfe9d4a53f695be2 to your computer and use it in GitHub Desktop.
Save grayskripko/c94a2ef0c1853205cfe9d4a53f695be2 to your computer and use it in GitHub Desktop.
Rowwise dplyr
# when you need to use tidyselect in a mutate function
# https://stackoverflow.com/questions/48353331/row-wise-operations-select-helpers-and-the-mutate-function-in-dplyr
tbl %>% mutate(a = select(., contains("abc")))
# based on https://rpubs.com/wch/200398
mtcars %>% purrrlyr::by_row(~any(is.na(.)), .collate = "rows", .to = "has_missing")
tibble(a=c(1, NA, 3), b=c(NA, 2, NA), c=c(NA, 5, 6)) %>%
mutate(pmap_int(., function(...) sum(lift_ld(is.na)(...))))
mtcars %>% split(seq(nrow(.))) %>% map...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment