insertCol: Insert a column into a data frame or matrix

Description Usage Arguments Value See Also Examples

View source: R/insertCol.r

Description

This function inserts one or more columns before or after another column in a data frame or matrix. It is similar to cbind except that the inserted column(s) can be placed anywhere.

Usage

1
insertCol(x, into, at, before = TRUE)

Arguments

x

Data frame, matrix, or vector with same number of rows or elements as into.

into

Data frame or matrix into which x is to be inserted.

at

Character or integer, name of column or column number at which to do insertion.

before

Logical, if TRUE (default) then the insertion will occur in front of the column named in at, if FALSE then after.

Value

A data frame.

See Also

merge, cbind

Examples

1
2
3
4
5
x <- data.frame(y1=11:15, y2=rev(letters)[1:5])
into <- data.frame(x1=1:5, x2='valid', x3=letters[1:5], x4=LETTERS[1:5], x5='stuff')

insertCol(x, into=into, at='x3')
insertCol(x, into=into, at='x3', before=FALSE)

adamlilith/omnibus documentation built on Nov. 21, 2018, 11:01 a.m.