combine: Combine R Objects With a Column Labeling the Source

Description Usage Arguments Details Author(s) See Also Examples

View source: R/combine.R

Description

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.

Usage

1

Arguments

...

vectors or matrices to combine.

names

character vector of names to use when creating source column.

Details

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.

Author(s)

Gregory R. Warnes greg@warnes.net

See Also

rbind, merge

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
a  <-  matrix(rnorm(12),ncol=4,nrow=3)
b  <-  1:4
combine(a,b)

combine(x=a,b)
combine(x=a,y=b)
combine(a,b,names=c("one","two"))

c <- 1:6
combine(b,c)

gdata documentation built on May 2, 2019, 5:49 p.m.