cbind.colnames {cwhmisc}R Documentation

Add columns to a data frame, using variable names.

Description

cbind.colnames adds columns to a given data frame. The names of the variables to be added are given in character vector add.

Usage

cbind.colnames(add,to=NULL,deparse.level = 1)

Arguments

to Matrix to be augmented.
add Vector of names of variables to be added to to as columns.
deparse.level Usually 1, See cbind

Value

Combined matrix. The column names are the concatenation of those of to and add. Row names are taken from to.

Note

Uses get to access the variables listed in add. If the new variables have wrong lenghts, an error will result.

Author(s)

Christian W. Hoffmann <c-w.hoffmann@sunrise.ch>
http://www.wsl.ch/personal_homepages/hoffmann/index_EN

Examples

d  <- data.frame(E = c("D","at","a"),w = c(11,22,33))
x  <- c(2,5,1)
ch <- c("I","have","fun")
F  <- factor(c("A","B","C"))
cbind.colnames(c("F","ch","x","F"),d)
#    E  w F   ch x F
# 1  D 11 A    I 2 A
# 2 at 22 B have 5 B
# 3  a 33 C  fun 1 C
cbind.colnames(c("x","F","ch","x"))
data.frame(x,F,ch,x) # the same
cbind.colnames(NULL) # NULL

[Package cwhmisc version 2.0.1 Index]