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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/verb-pivot-longer.R
\name{pivot_longer.tbl_lazy}
\alias{pivot_longer.tbl_lazy}
\title{Pivot data from wide to long}
\usage{
\method{pivot_longer}{tbl_lazy}(
data,
cols,
names_to = "name",
names_prefix = NULL,
names_sep = NULL,
names_pattern = NULL,
names_ptypes = NULL,
names_transform = NULL,
names_repair = "check_unique",
values_to = "value",
values_drop_na = FALSE,
values_ptypes,
values_transform = NULL,
...
)
}
\arguments{
\item{data}{A data frame to pivot.}
\item{cols}{Columns to pivot into longer format.}
\item{names_to}{A string specifying the name of the column to create
from the data stored in the column names of \code{data}.}
\item{names_prefix}{A regular expression used to remove matching text
from the start of each variable name.}
\item{names_sep, names_pattern}{If \code{names_to} contains multiple values,
these arguments control how the column name is broken up.}
\item{names_ptypes}{A list of column name-prototype pairs.}
\item{names_transform, values_transform}{A list of column name-function pairs.}
\item{names_repair}{What happens if the output has invalid column names?}
\item{values_to}{A string specifying the name of the column to create
from the data stored in cell values. If \code{names_to} is a character
containing the special \code{.value} sentinel, this value will be ignored,
and the name of the value column will be derived from part of the
existing column names.}
\item{values_drop_na}{If \code{TRUE}, will drop rows that contain only \code{NA}s
in the \code{value_to} column.}
\item{values_ptypes}{Not supported.}
\item{...}{Additional arguments passed on to methods.}
}
\description{
\code{pivot_longer()} "lengthens" data, increasing the number of rows and
decreasing the number of columns. The inverse transformation is
`tidyr::pivot_wider()]
Learn more in \code{vignette("pivot", "tidyr")}.
While most functionality is identical there are some differences to
\code{pivot_longer()} on local data frames:
\itemize{
\item the output is sorted differently/not explicitly,
\item the coercion of mixed column types is left to the database,
\item \code{values_ptypes} NOT supported.
}
Note that \code{build_longer_spec()} and \code{pivot_longer_spec()} do not work with
remote tables.
}
\details{
The SQL translation basically works as follows:
\enumerate{
\item split the specification by its key columns i.e. by variables crammed
into the column names.
\item for each part in the splitted specification \code{transmute()} \code{data} into the
following columns
}
\itemize{
\item id columns i.e. columns that are not pivotted
\item key columns
\item value columns i.e. columns that are pivotted
}
\enumerate{
\item combine all the parts with \code{union_all()}
}
}
\examples{
\dontshow{if (rlang::is_installed("tidyr", version = "1.0.0")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf}
# See vignette("pivot") for examples and explanation
# Simplest case where column names are character data
memdb_frame(
id = c("a", "b"),
x = 1:2,
y = 3:4
) \%>\%
tidyr::pivot_longer(-id)
\dontshow{\}) # examplesIf}
}
|