-
Notifications
You must be signed in to change notification settings - Fork 131
/
Copy pathadd_column.Rd
63 lines (55 loc) · 1.88 KB
/
add_column.Rd
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
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/add.R
\name{add_column}
\alias{add_column}
\title{Add columns to a data frame}
\usage{
add_column(
.data,
...,
.before = NULL,
.after = NULL,
.name_repair = c("check_unique", "unique", "universal", "minimal")
)
}
\arguments{
\item{.data}{Data frame to append to.}
\item{...}{<\code{\link[rlang:dyn-dots]{dynamic-dots}}>
Name-value pairs, passed on to \code{\link[=tibble]{tibble()}}. All values must have
the same size of \code{.data} or size 1.}
\item{.before, .after}{One-based column index or column name where to add the
new columns, default: after last column.}
\item{.name_repair}{Treatment of problematic column names:
\itemize{
\item \code{"minimal"}: No name repair or checks, beyond basic existence,
\item \code{"unique"}: Make sure names are unique and not empty,
\item \code{"check_unique"}: (default value), no name repair, but check they are
\code{unique},
\item \code{"universal"}: Make the names \code{unique} and syntactic
\item a function: apply custom name repair (e.g., \code{.name_repair = make.names}
for names in the style of base R).
\item A purrr-style anonymous function, see \code{\link[rlang:as_function]{rlang::as_function()}}
}
This argument is passed on as \code{repair} to \code{\link[vctrs:vec_as_names]{vctrs::vec_as_names()}}.
See there for more details on these terms and the strategies used
to enforce them.}
}
\description{
This is a convenient way to add one or more columns to an existing data
frame.
}
\examples{
# add_column ---------------------------------
df <- tibble(x = 1:3, y = 3:1)
df \%>\% add_column(z = -1:1, w = 0)
df \%>\% add_column(z = -1:1, .before = "y")
# You can't overwrite existing columns
try(df \%>\% add_column(x = 4:6))
# You can't create new observations
try(df \%>\% add_column(z = 1:5))
}
\seealso{
Other addition:
\code{\link{add_row}()}
}
\concept{addition}