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_row(.data, ..., .before = NULL, .after = NULL)

Arguments

.data

Data frame to append to.

...

Name-value pairs, passed on to tibble(). Only columns that exist in .data can be used, unset columns will get an NA value. These arguments are passed on to tibble(), and therefore also support unquote via !! and unquote-splice via !!!.

.before, .after

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

Details

add_case() is an alias of add_row().

See also

Other addition: add_column

Examples

# add_row --------------------------------- df <- tibble(x = 1:3, y = 3:1) add_row(df, x = 4, y = 0)
#> # A tibble: 4 x 2 #> x y #> <dbl> <dbl> #> 1 1 3 #> 2 2 2 #> 3 3 1 #> 4 4 0
# You can specify where to add the new rows add_row(df, x = 4, y = 0, .before = 2)
#> # A tibble: 4 x 2 #> x y #> <dbl> <dbl> #> 1 1 3 #> 2 4 0 #> 3 2 2 #> 4 3 1
# 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)
#> # A tibble: 5 x 2 #> x y #> <int> <int> #> 1 1 3 #> 2 2 2 #> 3 3 1 #> 4 4 0 #> 5 5 -1
# Absent variables get missing values add_row(df, x = 4)
#> # A tibble: 4 x 2 #> x y #> <dbl> <int> #> 1 1 3 #> 2 2 2 #> 3 3 1 #> 4 4 NA
# You can't create new variables
# NOT RUN { add_row(df, z = 10) # }