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

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1745488050, '3.144.97.63', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/R/functions/mean(80): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78