Means | R Documentation |
The function Means()
creates a table of group
means, optionally with standard errors, confidence intervals, and
numbers of valid observations.
Means(data, ...)
## S3 method for class 'data.frame'
Means(data,
by, weights=NULL, subset=NULL,
default=NA,
se=FALSE, ci=FALSE, ci.level=.95,
counts=FALSE, ...)
## S3 method for class 'formula'
Means(data, subset, weights, ...)
## S3 method for class 'numeric'
Means(data, ...)
## S3 method for class 'means.table'
as.data.frame(x, row.names=NULL, optional=TRUE, drop=TRUE, ...)
## S3 method for class 'xmeans.table'
as.data.frame(x, row.names=NULL, optional=TRUE, drop=TRUE, ...)
data |
an object usually containing data, or a formula. If If |
by |
a formula, a vector of variable names or a data frame or list of factors. If If If |
weights |
an optional vector of weights, usually a variable in |
subset |
an optional logical vector to select observations,
usually the result of an expression in variables from |
default |
a default value used for empty cells without observations. |
se |
a logical value, indicates whether standard errors should be computed. |
ci |
a logical value, indicates whether limits of confidence intervals should be computed. |
ci.level |
a number, the confidence level of the confidence interval |
counts |
a logical value, indicates whether numbers of valid observations should be reported. |
x |
for |
row.names |
an optional character vector. This argmument presently is
inconsequential and only included for reasons of compatiblity
with the standard methods of |
optional |
an optional logical value. This argmument presently is
inconsequential and only included for reasons of compatiblity
with the standard methods of |
drop |
a logical value, determines whether "empty cells" should be dropped from the resulting data frame. |
... |
other arguments, either ignored or passed on to other methods where applicable. |
An array that inherits classes "means.table" and "table". If
Means
was called with se=TRUE
or ci=TRUE
then the result additionally inherits class "xmeans.table".
# Preparing example data
USstates <- as.data.frame(state.x77)
USstates <- within(USstates,{
region <- state.region
name <- state.name
abb <- state.abb
division <- state.division
})
USstates$w <- sample(runif(n=6),size=nrow(USstates),replace=TRUE)
# Using the data frame method
Means(USstates[c("Murder","division","region")],by=c("division","region"))
Means(USstates[c("Murder","division","region")],by=USstates[c("division","region")])
Means(USstates[c("Murder")],1)
Means(USstates[c("Murder","region")],by=c("region"))
# Using the formula method
# One 'dependent' variable
Means(Murder~1, data=USstates)
Means(Murder~division, data=USstates)
Means(Murder~division, data=USstates,weights=w)
Means(Murder~division+region, data=USstates)
as.data.frame(Means(Murder~division+region, data=USstates))
# Standard errors and counts
Means(Murder~division, data=USstates, se=TRUE, counts=TRUE)
drop(Means(Murder~division, data=USstates, se=TRUE, counts=TRUE))
as.data.frame(Means(Murder~division, data=USstates, se=TRUE, counts=TRUE))
# Confidence intervals
Means(Murder~division, data=USstates, ci=TRUE)
drop(Means(Murder~division, data=USstates, ci=TRUE))
as.data.frame(Means(Murder~division, data=USstates, ci=TRUE))
# More than one dependent variable
Means(Murder+Illiteracy~division, data=USstates)
as.data.frame(Means(Murder+Illiteracy~division, data=USstates))
# Confidence intervals
Means(Murder+Illiteracy~division, data=USstates, ci=TRUE)
as.data.frame(Means(Murder+Illiteracy~division, data=USstates, ci=TRUE))
# Some 'non-standard' but still valid usages:
with(USstates,
Means(Murder~division+region,subset=region!="Northeast"))
with(USstates,
Means(Murder,by=list(division,region)))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.