insert_row: Insert a new row into a data frame

View source: R/insert_row.R

insert_rowR Documentation

Insert a new row into a data frame

Description

Insert a new row into a data frame

Usage

insert_row(df, newrow, r)

Arguments

df

a data frame

newrow

new row to insert, must have same columns as df

r

row index indicating where new row will be inserted

Value

Returns a data frame with an extra row inserted at specified index

Examples

# example dataframe
d <- as.data.frame(matrix(seq(20), nrow=5, ncol=4))

# row number that you want to insert
r <- 3

# create a new row to insert
newrow <- seq(4)
# can be a subset of original dataframe
newrow2 <- d[1, ]

# insert row
insert_row(d, newrow, r)
insert_row(d, newrow2, r)

avrincon/phdfuns documentation built on Nov. 13, 2022, 10:34 a.m.