1.12
The dplyr::summarize
is often used in conjunction with the group_by
function, to calculate statistics by group.
# calculate mean height and weight by gender
newdata <- group_by(starwars, gender)
newdata <- summarize(newdata,
mean_ht = mean(height, na.rm=TRUE),
mean_wt = mean(mass, na.rm=TRUE))
newdata
## # A tibble: 3 × 3
## gender mean_ht mean_wt
## <chr> <dbl> <dbl>
## 1 feminine 167. 54.7
## 2 masculine 177. 107.
## 3 <NA> 175 81