The R Project SVN R

Rev

Rev 84199 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 84199 Rev 88886
Line 1... Line 1...
1
% File src/library/base/man/by.Rd
1
% File src/library/base/man/by.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-2014 R Core Team
3
% Copyright 1995-2025 R Core Team
4
% Distributed under GPL 2 or later
4
% Distributed under GPL 2 or later
5
 
5
 
6
\name{by}
6
\name{by}
7
\alias{by}
7
\alias{by}
8
\alias{by.default}
8
\alias{by.default}
Line 20... Line 20...
20
 \item{data}{an \R object, normally a data frame, possibly a matrix.}
20
 \item{data}{an \R object, normally a data frame, possibly a matrix.}
21
 \item{INDICES}{a factor or a list of factors, each of length
21
 \item{INDICES}{a factor or a list of factors, each of length
22
   \code{nrow(data)}. For the data frame method, \code{INDICES} can also
22
   \code{nrow(data)}. For the data frame method, \code{INDICES} can also
23
   be a formula as in the \code{f} argument of the \code{\link{split}}
23
   be a formula as in the \code{f} argument of the \code{\link{split}}
24
   method for data frames.}
24
   method for data frames.}
25
 \item{FUN}{a function to be applied to (usually data-frame) subsets of
25
 \item{FUN}{a \code{\link{function}} to be applied to (usually data-frame)
26
   \code{data}.}
26
   subsets of \code{data}.}
27
 \item{\dots}{further arguments to \code{FUN}.}
27
 \item{\dots}{further arguments to \code{FUN}.}
28
 \item{simplify}{logical: see \code{\link{tapply}}.}
28
 \item{simplify}{logical: see \code{\link{tapply}}.}
29
}
29
}
30
\details{
30
\details{
31
  A data frame is split by row into data frames
31
  A data frame is split (calling \code{\link{split}()} by row into data frames
32
  subsetted by the values of one or more factors, and function
32
  subsetted by the values of one or more factors, and function
33
  \code{FUN} is applied to each subset in turn.
33
  \code{FUN} is applied to each subset in turn.
34
 
34
 
35
  For the default method, an object with dimensions (e.g., a matrix) is
35
  For the default method, an object with dimensions (e.g., a matrix) is
36
  coerced to a data frame and the data frame method applied.  Other
36
  coerced to a data frame and the data frame method applied.  Other
Line 58... Line 58...
58
            by(warpbreaks, tension,
58
            by(warpbreaks, tension,
59
               function(x) lm(breaks ~ wool, data = x)))
59
               function(x) lm(breaks ~ wool, data = x)))
60
sapply(tmp1, coef)
60
sapply(tmp1, coef)
61
 
61
 
62
## another way
62
## another way
63
tmp2 <- by(warpbreaks, ~ tension,
63
by(warpbreaks, ~ tension,
64
           with, coef(lm(breaks ~ wool)))
64
   with, coef(lm(breaks ~ wool))) |> array2DF(simplify = TRUE)
65
array2DF(tmp2, simplify = TRUE)
-
 
66
}
65
}
67
\keyword{iteration}
66
\keyword{iteration}
68
\keyword{category}
67
\keyword{category}