Skip to content

Latest commit

 

History

History
35 lines (26 loc) · 1.11 KB

tidyverse-forget.md

File metadata and controls

35 lines (26 loc) · 1.11 KB

Tidyverse functions that I always forget

Jessica Minnier 2019-05-10

  • tibble::enframe() converts a named vector to a tibble and tibble::deframe() does the opposite
  • forcats::fct_infreq() reorders a character or factor column in place, and can be used in ggplot:
ggplot(mtcars %>% mutate(carb = as.character(carb)), aes(fct_infreq(carb),fill=carb)) + geom_bar()

  • stringr::str_detect can be used to search for multiple strings in a vector by using paste collapse:
fruit <- c("apple", "banana", "pear", "pinapple")
mystrings <- c("apple","pear","grape")
str_detect(fruit, paste(mystrings,collapse="|"))
#> [1]  TRUE FALSE  TRUE  TRUE