File: by-split.Rd

package info (click to toggle)
r-cran-doby 4.7.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,400 kB
  • sloc: makefile: 2
file content (82 lines) | stat: -rw-r--r-- 1,916 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/by_splitBy.R
\name{by-split}
\alias{by-split}
\alias{split_by}
\alias{splitBy}
\alias{head.splitByData}
\alias{tail.splitByData}
\alias{split_by.legacy}
\alias{splitBy.legacy}
\title{Split a data frame into groups defined by variable(s)}
\usage{
split_by(data., ..., omit = TRUE)

splitBy(formula, data, omit = TRUE)

\method{head}{splitByData}(x, n = 6L, ...)

\method{tail}{splitByData}(x, n = 6L, ...)

split_by.legacy(data, formula, drop = TRUE)

splitBy.legacy(formula, data = parent.frame(), drop = TRUE)
}
\arguments{
\item{data.}{A data frame (or tibble) to split}

\item{...}{Variables defining the groups}

\item{omit}{If TRUE (default), group-defining variables are omitted in each split group}

\item{formula}{A right hand sided formula (for the old interface)}

\item{data}{A data frame  (for the old interface)}

\item{x}{A splitByData object.}

\item{n}{An integer vector.}

\item{drop}{Obsolete}
}
\value{
An object of class \"splitByData\" (a named list with group attributes)
}
\description{
Split a dataframe according to the levels of variables
in the dataframe. Uses vparse() to interpret flexible input.
}
\examples{

split_by(CO2, ~Treatment+Type)
split_by(CO2, Treatment, Type)
split_by(CO2, c("Treatment", "Type"))
split_by(CO2, "Treatment", "Type")

x <- split_by(CO2, "Treatment", "Type")
head(x, 3)
tail(x, 3)

## Via wrapper:
foo2 <- function(x) {
 x <- rlang::enquo(x)
 split_by(CO2, !!x)
}
foo2(~Treatment)

## The "Old" interface
splitBy(~Treatment + Type, CO2)
splitBy(~Treatment + Type, data=CO2)
splitBy(c("Treatment", "Type"), data=CO2)

}
\seealso{
\code{\link{orderBy}}, \code{\link{order_by}},
\code{\link{summaryBy}}, \code{\link{summary_by}},
\code{\link{transformBy}}, \code{\link{transform_by}}
}
\author{
Søren Højsgaard, \email{sorenh@math.aau.dk}
}
\concept{byfunction}
\keyword{utilities}