Adds a new row to a data frame at a specified position
Usage
add_record(.data, ..., .before = NULL, .after = NULL)
Arguments
- .data
A data frame to which a record will be added
- ...
New record to be added (vector, list, or data frame)
- .before
Optional. Row number before which to insert the new record
- .after
Optional. Row number after which to insert the new record
Value
Modified data frame with the new record inserted
Examples
df <- data.frame(x = 1:3, y = 4:6)
add_record(df, c(4, 7))
#> x y
#> 1 1 4
#> 2 2 5
#> 3 3 6
#> 4 4 7
add_record(df, c(4, 7), .before = 2)
#> x y
#> 1 1 4
#> 2 4 7
#> 21 2 5
#> 3 3 6