1.11 Summarizing data
The dplyr::summarize
function can be used to reduce multiple values down to a single value (such as a mean).
library(dplyr)
# calculate mean height and mass
newdata <- summarize(starwars,
mean_ht = mean(height, na.rm=TRUE),
mean_mass = mean(mass, na.rm=TRUE))
newdata
## # A tibble: 1 × 2
## mean_ht mean_mass
## <dbl> <dbl>
## 1 175. 97.3