insertCol {omnibus}R Documentation

Insert a column or row into a data frame or matrix

Description

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

Usage

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

insertRow(x, into, at = NULL, before = TRUE)

Arguments

x

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

into

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

at

Character, integer, or NULL. Name of column or column number or name of row or row number at which to do insertion. If NULL (default), the result is exactly the same as cbind(into, x except that it retains row numbers or column names from into.

before

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

Value

A data frame.

Functions

See Also

merge, cbind, insert

Examples


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)
insertCol(x, into)

x <- data.frame(x1=1:3, x2=LETTERS[1:3])
into <- data.frame(x1=11:15, x2='valid')
row.names(into) <- letters[1:5]

insertRow(x, into=into, at='b')
insertRow(x, into=into, at='b', before=FALSE)
insertRow(x, into)


[Package omnibus version 1.2.13 Index]