add_column: Add columns to a data frame

Description Usage Arguments See Also Examples

View source: R/add.R

Description

This is a convenient way to add one or more columns to an existing data frame.

Usage

1
add_column(.data, ..., .before = NULL, .after = NULL)

Arguments

.data

Data frame to append to.

...

Name-value pairs, passed on to tibble(). All values must have one element for each row in the data frame, or be of length 1. These arguments are passed on to tibble(), and therefore also support unquote via !! and unquote-splice via !!!. However, unlike in dplyr verbs, columns in .data are not available for the expressions. Use dplyr::mutate() if you need to add a column based on existing data.

.before, .after

One-based column index or column name where to add the new columns, default: after last column.

See Also

Other addition: add_row()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# add_column ---------------------------------
df <- tibble(x = 1:3, y = 3:1)

add_column(df, z = -1:1, w = 0)

# You can't overwrite existing columns
## Not run: 
add_column(df, x = 4:6)

## End(Not run)
# You can't create new observations
## Not run: 
add_column(df, z = 1:5)

## End(Not run)

krlmlr/tibble documentation built on Jan. 15, 2020, 7:56 a.m.