rbind-fill: Bind matrices by row, and fill missing columns with NA

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

Description

The matrices are bound together using their column names or the column indices (in that order of precedence.) Numeric columns may be converted to character beforehand, e.g. using format. If a matrix doesn't have colnames, the column number is used.

The matrices are bound together using their column names or the column indices (in that order of precedence.) Numeric columns may be converted to character beforehand, e.g. using format. If a matrix doesn't have colnames, the column number is used (via make.names(unique = TRUE)).

This is an enhancement to rbind which adds in columns that are not present in all inputs, accepts a list of data frames, and operates substantially faster

Usage

1
2
3
4
5

Arguments

...

data frames/matrices to row bind together

Details

Note that this means that a column with name "X1" is merged with the first column of a matrix without name and so on.

Vectors are converted to 1-column matrices prior to rbind.

Matrices of factors are not supported. (They are anyways quite inconvenient.) You may convert them first to either numeric or character matrices. If a character matrix is merged with a numeric, the result will be character.

Row names are ignored.

The return matrix will always have column names.

Value

a matrix

a matrix

Author(s)

C. Beleites

C. Beleites

See Also

rbind, cbind, rbind.fill

rbind, cbind, rbind.fill

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
A <- matrix (1:4, 2)
 B <- matrix (6:11, 2)
 A
 B
 rbind.fill.matrix (A, B)

 colnames (A) <- c (3, 1)
 A
 rbind.fill.matrix (A, B)
A <- matrix (1:4, 2)
 B <- matrix (6:11, 2)
 A
 B
 rbind.fill.matrix (A, B)

 colnames (A) <- c (3, 1)
 A
 rbind.fill.matrix (A, B)

 rbind.fill.matrix (A, 99)
#' rbind.fill(mtcars[c("mpg", "wt")], mtcars[c("wt", "cyl")])

Example output

Loading required package: lattice
Loading required package: grid
Loading required package: ggplot2
Package hyperSpec, version 0.98-20161118

To get started, try
   vignette ("introduction", package = "hyperSpec")
   package?hyperSpec 
   vignette (package = "hyperSpec")

If you use this package please cite it appropriately.
   citation("hyperSpec")
will give you the correct reference.

The project homepage is http://hyperspec.r-forge.r-project.org


     [,1] [,2]
[1,]    1    3
[2,]    2    4
     [,1] [,2] [,3]
[1,]    6    8   10
[2,]    7    9   11
     X1 X2 X3
[1,]  1  3 NA
[2,]  2  4 NA
[3,]  6  8 10
[4,]  7  9 11
     3 1
[1,] 1 3
[2,] 2 4
      3  1 X1 X2 X3
[1,]  1  3 NA NA NA
[2,]  2  4 NA NA NA
[3,] NA NA  6  8 10
[4,] NA NA  7  9 11
     [,1] [,2]
[1,]    1    3
[2,]    2    4
     [,1] [,2] [,3]
[1,]    6    8   10
[2,]    7    9   11
     X1 X2 X3
[1,]  1  3 NA
[2,]  2  4 NA
[3,]  6  8 10
[4,]  7  9 11
     3 1
[1,] 1 3
[2,] 2 4
      3  1 X1 X2 X3
[1,]  1  3 NA NA NA
[2,]  2  4 NA NA NA
[3,] NA NA  6  8 10
[4,] NA NA  7  9 11
      3  1 X1
[1,]  1  3 NA
[2,]  2  4 NA
[3,] NA NA 99

hyperSpec documentation built on May 31, 2017, 3:47 a.m.