mean
Mean Value (Arithmetic Average)

### Description

Returns a number that is the mean of the data. You can specify a fraction to trim from each end of the ordered data. The function mean is generic.

### Usage

    mean(x, ...)
    ## Default S3 method:
    mean(x, na.rm = FALSE)
    ## S3 method for class 'Date':
    mean(x, ...)
    ## S3 method for class 'POSIXct':
    mean(x, ...)
    ## S3 method for class 'POSIXlt':
    mean(x, ...)
    ## S3 method for class 'difftime':
    mean(x, ..., na.rm = FALSE)
    ## S3 method for class 'data.frame':
    mean(x, na.rm = FALSE)

### Arguments

x | a numeric object. Missing values (NA) are allowed.
... | additional arguments passed to mean, such as trim and na.rm.

### Details

If x contains NAs, the result is NA, unless you specify na.rm=TRUE.
If x is a factor or data.frame, mean produces a warning, and the result is NA.
If you pass the argument trim as a positive, floor(trim*length(x)) is the number of elements to be ignored.
If you specify trim = .25, the result is often called the "midmean".
Value

mean | returns the (trimmed) mean of x.
mean.Date | returns a Date object representing the mean of x.
mean.POSIXlt | returns a POSIXlt object representing the mean of x.
mean.POSIXct | returns a POSIXct object representing the mean of x.
mean.difftime | returns a difftime object representing the mean of x.
mean.data.frame | returns a numeric NA, with a warning that you should use sapply(x,mean) or colMeans(x)

References
Hoaglin, D. C., Mosteller, F. and Tukey, J. W., editors (1983). Understanding Robust and Exploratory Data Analysis. Wiley, New York.
See Also
apply, colMeans, median, var.
Examples

    testscores <- data.frame(oct=sample(30:100, 25), nov=sample(30:100, 25),
        dec=sample(30:100,25))
    algebra <- testscores[,3]  # vector of 25 algebra testscores
    mean(algebra)   # Computes the average
    mean(algebra, trim=0.1)  # Computes the 10% trimmed mean of scores
    # vector of the means of the columns of scores
    apply(testscores, 2, mean)
    ## date-time objects
    mean(Sys.Date() + 1:5)
    mean(Sys.time() + 1:5)
    mean(as.POSIXlt(Sys.time() + 1:5))
    mean(Sys.time() - as.POSIXct(Sys.Date()) + 1:5)

Package base version 6.1.5-18
Package Index