rbind.smart: A smarter rbind 'rbind' 2 matrix-like-objects even if they...

Description Usage Arguments Details Value Author(s) See Also Examples

Description

The resulting data.frame will have nrow(x) + nrow(y) rows, and length(union(colnames(x), colnames(y))) columns.

Usage

1
rbind.smart(x, y, sort.col = NULL)

Arguments

x, y

matrix-like objects to be merged

sort.col

Which column would you like the resulting data to be sorted on? Set to NULL to disable, in which case, rows corresponding to x will appear before those from y.

Details

If x and y contain the same colnames, then rbind.smart == rbind.

If x and y contain partially overlapping colnames, then the result will be the union of all colnames, with NA's filled in where appropriate.

If x and y contain no overlapping colnames, then the result will have x in top left and y in bottom right, filled in with NA's. as in:

1
2
 x
: X; y: Y rbind.smart(x, y) -> X NA NA Y 

Naming rules: column classes from x take precedence over those from y, and the colnames of result will be all of the colnames from x, then the colnames from y that were not also in x at the end.

Value

A data.frame with nrow(x) + nrow(y) rows, and length(union(colnames(x), colnames(y))) columns.

Author(s)

Mark Cowley, 11 April 2006

See Also

rbind

Examples

1
2
3
4
5
a <- matrix(rnorm(25), 5, 5)
colnames(a) <- letters[1:5]
b <- matrix(rnorm(25), 5, 5)
colnames(b) <- letters[3:7]
rbind.smart(a, b)

drmjc/mjcbase documentation built on May 15, 2019, 2:27 p.m.