spatialEco (version 1.3-2)

insert: Insert a row or column into a data.frame

Description

Inserts a new row or column into a data.frame at a specified location

Usage

insert(x, MARGIN = 1, value = NULL, idx, name = NULL)

Arguments

x

Existing data.frame

MARGIN

Insert a 1 = row or 2 = column

value

A vector of values equal to the length of MARGIN, if nothing specified values with be NA

idx

Index position to insert row or column

name

Name of new column (not used for rows, MARGIN=1)

Value

A data.frame with the new row or column inserted

Examples

Run this code
# NOT RUN {
d <- data.frame(ID=1:10, y=runif(10))

# insert row
insert(d, idx=2)
insert(d, value=c(20,0), idx=2)

# insert column
insert(d, MARGIN=2, idx=2)
insert(d, MARGIN = 2, value = rep(0,10), idx=2, name="x")

# }

Run the code above in your browser using DataLab