<chr> 1 Luke Skywalker 2 C-3PO 3 R2-D2 # … with 84 more rows starwars %>% transmute(1) # A tibble: 87 x 1 `1` <dbl> 1 1 2 1 3 1 # … with 84 more rows Sometimes they appear to work the same way...
x 13 # Groups: gender [5] name height mass hair_color skin_color eye_color <chr> <int> <dbl> <chr> <chr> <chr> 1 Luke… 172 77 blond fair blue 2 C-3PO 167 75 NA gold yellow 3 R2-D2 96 32 NA white, bl… red # … with 84 more rows, and 7 more variables
They take selections within vars(...) • mutate_at() and summarise_at() apply a function on each of those vars 1. Selections with dplyr mutate_at() summarise_at() filter_at() rename_at() arrange_at()
x 5 gender height_mean mass_mean height_sd mass_sd <chr> <dbl> <dbl> <dbl> <dbl> 1 female 165. 54.0 23.0 8.37 2 hermaphrodite 175 1358 NA NA 3 male 179. 81.0 35.4 28.2 4 none 200 140 NA NA 5 NA 120 46.3 40.7 24.8 Works with groups!
bmi = mass / heightm^2 ) Warning messages: 1: In mean.default(Value, na.rm = TRUE) : argument is not numeric or logical: returning NA 2: In mean.default(Value, na.rm = TRUE) : argument is not numeric or logical: returning NA 3: In mean.default(Value, na.rm = TRUE) : argument is not numeric or logical: returning NA • gather() also gathers grouping variables • Summaries can't be applied on character
Do you need actions or selections? • The _at variants and transmute() are useful • Requires knowledge of tidyverse verbs — transferable • Think about grouped tibbles summary()