\Header{ave}{Group Averages Over Level Combinations of Factors}
\keyword{univar}{ave}
\begin{Usage}
\begin{verbatim}
ave(x, ..., FUN = mean)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\texttt{x}] A numeric.
\item[\texttt{...}] Grouping variables, typically factors, all of the same
\texttt{length} as \texttt{x}.
\item[\texttt{FUN}] Function to apply for each factor level combination.
\end{ldescription}
\end{Arguments}
\begin{Description}
Subsets of \texttt{x[]} are averaged, where each subset consist of those
observations with the same factor levels.\end{Description}
\begin{Value}
A numeric vector, say \texttt{y} of length \texttt{length(x)}.
If \texttt{...} is \texttt{g1,g2}, e.g.,
\texttt{y[i]} is equal to \texttt{FUN(x[j]}, for all \texttt{j} with
\texttt{g1[j]==g1[i]} and \texttt{g2[j]==g2[i])}.\end{Value}
\begin{SeeAlso}
\texttt{\Link{mean}}, \texttt{\Link{median}}.\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
data(warpbreaks)
attach(warpbreaks)
ave(breaks, wool)
ave(breaks, tension)
ave(breaks, tension, FUN = function(x)mean(x, trim=.1))
plot(breaks, main =
     "ave( Warpbreaks )  for   wool  x  tension  combinations")
lines(ave(breaks, wool, tension            ), type='s', col = "blue")
lines(ave(breaks, wool, tension, FUN=median), type='s', col = "green")
legend(40,70, c("mean","median"), lty=1,col=c("blue","green"), bg="gray90")
detach()
\end{ExampleCode}
\end{Examples}

