Search notes:

R function: mean

#   See also
#     -> summary()
#

d <- c (0:10)

mean(d)
# [1] 5

#
# The mean can also more verbosely be expressed like so:
#
sum(d) / length(d)
# [1] 5

d <- append(d, NA)

mean(d, na.rm=TRUE )
# [1] 5

mean(d, na.rm=FALSE)
# [1] NA
#

#
#      Trimmed mean:
#

e <- c(  12, 19, 36, 38, 39, 40, 42, 44, 66, 91)
mean(e, trim=0.2) # Trim 20% on either side
# [1] 39.83333
Github repository about-r, path: /functions/mean.R
With mean, it's possible to calculate the relative frequency of observations in a sample. The following example shows that a third of words is equal to foo:
words <- c('foo', 'bar', 'bar', 'foo', 'baz', 'bar', 'baz', 'foo', 'bar', 'bar', 'foo', 'baz')

mean(words == 'foo')
#
# [1] 0.3333333
Github repository about-r, path: /examples/relative-frequency.R

See also

summary
Index to (some) R functions

Index