The R Project SVN R

Rev

Rev 72508 | Rev 84060 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 72508 Rev 75988
Line 1... Line 1...
1
% File src/library/base/man/tapply.Rd
1
% File src/library/base/man/tapply.Rd
2
% Part of the R package, https://www.R-project.org
2
% Part of the R package, https://www.R-project.org
3
% Copyright 1995-2017 R Core Team
3
% Copyright 1995-2019 R Core Team
4
% Distributed under GPL 2 or later
4
% Distributed under GPL 2 or later
5
 
5
 
6
\name{tapply}
6
\name{tapply}
7
\alias{tapply}
7
\alias{tapply}
8
\title{Apply a Function Over a Ragged Array}
8
\title{Apply a Function Over a Ragged Array}
Line 19... Line 19...
19
    exists.  Typically vector-like, allowing subsetting with
19
    exists.  Typically vector-like, allowing subsetting with
20
    \code{\link{[}}.}
20
    \code{\link{[}}.}
21
  \item{INDEX}{a \code{\link{list}} of one or more \code{\link{factor}}s,
21
  \item{INDEX}{a \code{\link{list}} of one or more \code{\link{factor}}s,
22
    each of same length as \code{X}.  The elements are coerced to
22
    each of same length as \code{X}.  The elements are coerced to
23
    factors by \code{\link{as.factor}}.}
23
    factors by \code{\link{as.factor}}.}
24
  \item{FUN}{the function to be applied, or \code{NULL}.  In the case of
24
  \item{FUN}{a function (or name of a function) to be applied, or \code{NULL}.
25
    functions like \code{+}, \code{\%*\%}, etc., the function name must
25
    In the case of functions like \code{+}, \code{\%*\%}, etc.,
26
    be backquoted or quoted.  If \code{FUN} is \code{NULL}, tapply
26
    the function name must be backquoted or quoted.  If \code{FUN} is
27
    returns a vector which can be used to subscript the multi-way array
27
    \code{NULL}, tapply returns a vector which can be used to subscript
28
    \code{tapply} normally produces.}
28
    the multi-way array \code{tapply} normally produces.}
29
  \item{\dots}{optional arguments to \code{FUN}: the Note section.}
29
  \item{\dots}{optional arguments to \code{FUN}: the Note section.}
30
  \item{default}{(only in the case of simplification to an array) the
30
  \item{default}{(only in the case of simplification to an array) the
31
    value with which the array is initialized as
31
    value with which the array is initialized as
32
    \code{\link{array}(default, dim = ..)}.  Before \R 3.4.0, this
32
    \code{\link{array}(default, dim = ..)}.  Before \R 3.4.0, this
33
    was hard coded to \code{\link{array}()}'s default \code{NA}.  If it
33
    was hard coded to \code{\link{array}()}'s default \code{NA}.  If it
Line 40... Line 40...
40
    an array of mode \code{"list"}; in other words, a \code{\link{list}}
40
    an array of mode \code{"list"}; in other words, a \code{\link{list}}
41
    with a \code{\link{dim}} attribute.  If \code{TRUE} (the default), then if
41
    with a \code{\link{dim}} attribute.  If \code{TRUE} (the default), then if
42
    \code{FUN} always returns a scalar, \code{tapply} returns an array
42
    \code{FUN} always returns a scalar, \code{tapply} returns an array
43
    with the mode of the scalar.}
43
    with the mode of the scalar.}
44
}
44
}
-
 
45
 
45
\value{
46
\details{
46
  If \code{FUN} is not \code{NULL}, it is passed to
47
  If \code{FUN} is not \code{NULL}, it is passed to
47
  \code{\link{match.fun}}, and hence it can be a function or a symbol or
48
  \code{\link{match.fun}}, and hence it can be a function or a symbol or
48
  character string naming a function.
49
  character string naming a function.
-
 
50
}
49
 
51
 
-
 
52
\value{
50
  When \code{FUN} is present, \code{tapply} calls \code{FUN} for each
53
  When \code{FUN} is present, \code{tapply} calls \code{FUN} for each
51
  cell that has any data in it.  If \code{FUN} returns a single atomic
54
  cell that has any data in it.  If \code{FUN} returns a single atomic
52
  value for each such cell (e.g., functions \code{mean} or \code{var})
55
  value for each such cell (e.g., functions \code{mean} or \code{var})
53
  and when \code{simplify} is \code{TRUE}, \code{tapply} returns a
56
  and when \code{simplify} is \code{TRUE}, \code{tapply} returns a
54
  multi-way \link{array} containing the values, and \code{NA} for the
57
  multi-way \link{array} containing the values, and \code{NA} for the
Line 56... Line 59...
56
  \code{INDEX} has components; the number of levels in a dimension is
59
  \code{INDEX} has components; the number of levels in a dimension is
57
  the number of levels (\code{nlevels()}) in the corresponding component
60
  the number of levels (\code{nlevels()}) in the corresponding component
58
  of \code{INDEX}.  Note that if the return value has a class (e.g., an
61
  of \code{INDEX}.  Note that if the return value has a class (e.g., an
59
  object of class \code{"\link{Date}"}) the class is discarded.
62
  object of class \code{"\link{Date}"}) the class is discarded.
60
 
63
 
61
  Note that contrary to S, \code{simplify = TRUE} always returns an
-
 
62
  array, possibly 1-dimensional.
64
  \code{simplify = TRUE} always returns an array, possibly 1-dimensional.
63
 
65
 
64
  If \code{FUN} does not return a single atomic value, \code{tapply}
66
  If \code{FUN} does not return a single atomic value, \code{tapply}
65
  returns an array of mode \code{\link{list}} whose components are the
67
  returns an array of mode \code{\link{list}} whose components are the
66
  values of the individual calls to \code{FUN}, i.e., the result is a
68
  values of the individual calls to \code{FUN}, i.e., the result is a
67
  list with a \code{\link{dim}} attribute.
69
  list with a \code{\link{dim}} attribute.