mean: Arithmetic mean

View source: R/mean.R

meanR Documentation

Arithmetic mean

Description

Calculates the arithmetic mean of a numeric vector.

Details

The first argument x is a numeric vector. Setting na.rm = TRUE will remove NA's in the vector before calculating the mean.

mean(x, na.rm = FALSE)

See Also

min(), max(), median(), quantile()

Examples

c(1, 2, 3) %>% mean()
#> [1] 2

-----------------------------------

# Missing values

c(1, 2, NA) %>% mean()
#> [1] NA

c(1, 2, NA) %>% mean(na.rm = T)
#> [1] 1.5

-----------------------------------

library(gapminder)

# Average life expectancy of countries
# each year:

gapminder %>%
  group_by(year) %>%
  summarize(lifeExp_mean = mean(lifeExp))

#> A tibble: 12 x 2
#>    year lifeExp_mean
     <int>        <dbl>
#> 1  1952         49.1
#> 2  1957         51.5
#> 3  1962         53.6


cobriant/qelp documentation built on July 1, 2022, 7:24 a.m.