Learn R Programming

cwhmisc (version 3.0)

cbind.colnames: 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.

Examples

Run this code
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

Run the code above in your browser using DataLab