Combine R Objects With a Column Labeling the Source

Take a sequence of vector, matrix or data frames and combine into rows of a common data frame with an additional column source indicating the source object.

manip, array
combine(..., names=NULL)

vectors or matrices to combine.


character vector of names to use when creating source column.


If there are several matrix arguments, they must all have the same number of columns. The number of columns in the result will be one larger than the number of columns in the component matrixes. If all of the arguments are vectors, these are treated as single column matrixes. In this case, the column containing the combineinated vector data is labeled data.

When the arguments consist of a mix of matrices and vectors the number of columns of the result is determined by the number of columns of the matrix arguments. Vectors are considered row vectors and have their values recycled or subsetted (if necessary) to achieve this length.

The source column is created as a factor with levels corresponding to the name of the object from which the each row was obtained. When the names argument is ommitted, the name of each object is obtained from the specified argument name in the call (if present) or from the name of the object. See below for examples.

See Also

rbind, merge

  • combine

a  <-  matrix(rnorm(12),ncol=4,nrow=3)
b  <-  1:4


c <- 1:6
Documentation reproduced from package gdata, version 2.18.0, License: GPL-2

Community examples

Looks like there are no examples yet.