This is a convenient way to add one or more columns to an existing data frame.
add_column(.data, ..., .before = NULL, .after = NULL)
.data | Data frame to append to. |
---|---|
... | Name-value pairs, passed on to |
.before, .after | One-based column index or column name where to add the new columns, default: after last column. |
Other addition: add_row
# add_column --------------------------------- df <- tibble(x = 1:3, y = 3:1) add_column(df, z = -1:1, w = 0)#> # A tibble: 3 x 4 #> x y z w #> <int> <int> <int> <dbl> #> 1 1 3 -1 0 #> 2 2 2 0 0 #> 3 3 1 1 0# You can't overwrite existing columns if (FALSE) { add_column(df, x = 4:6) } # You can't create new observations if (FALSE) { add_column(df, z = 1:5) }