add_row: Add rows to a data frame

Description Usage Arguments Life cycle See Also Examples

View source: R/add.R

Description

\lifecycle

questioning

This is a convenient way to add one or more rows of data to an existing data frame. See tribble() for an easy way to create an complete data frame row-by-row.

add_case() is an alias of add_row().

Usage

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

Arguments

.data

Data frame to append to.

...

Name-value pairs, passed on to tibble(). Values can be defined only for columns that already exist in .data and unset columns will get an NA value. 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.

.before, .after

One-based row index where to add the new rows, default: after last row.

Life cycle

It is unclear if add_row() and its alias add_cases() should ensure that all columns have length one by wrapping in a list if necessary. See https://github.com/tidyverse/tibble/pull/503 and https://github.com/tidyverse/tibble/issues/205 for details.

See Also

Other addition: add_column()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
# add_row ---------------------------------
df <- tibble(x = 1:3, y = 3:1)

add_row(df, x = 4, y = 0)

# You can specify where to add the new rows
add_row(df, x = 4, y = 0, .before = 2)

# You can supply vectors, to add multiple rows (this isn't
# recommended because it's a bit hard to read)
add_row(df, x = 4:5, y = 0:-1)

# Absent variables get missing values
add_row(df, x = 4)

# You can't create new variables
## Not run: 
add_row(df, z = 10)

## End(Not run)

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