Learn R Programming

DataCombine (version 0.2.21)

InsertRow: Inserts a new row into a data frame

Description

Inserts a new row into a data frame

Usage

InsertRow(data, NewRow, RowNum = NULL)

Arguments

data
a data frame to insert the new row into.
NewRow
a vector whose length is the same as the number of columns in data.
RowNum
numeric indicating which row to insert the new row as. If not specified then the new row is added to the end using a vanilla rbind call.

Source

The function largely implements: http://stackoverflow.com/a/11562428

Examples

Run this code
# Create dummy data
A <- B <- C <- D <- sample(1:20, size = 20, replace = TRUE)
Data <- data.frame(A, B, C, D)

# Create new row
New <- rep(1000, 4)

# Insert into 4th row
Data <- InsertRow(Data, NewRow = New, RowNum = 4)

Run the code above in your browser using DataLab