Matrix.utils (version 0.9.1)

rBind.fill: Combine matrixes by row, fill in missing columns

Description

rbinds a list of Matrix or matrix like objects, filling in missing columns.

Usage

rBind.fill(x, ..., fill = NA)

Arguments

x, ...
Objects to combine. If the first argument is a list and .. is unpopulated, the objects in that list will be combined.
fill
value with which to fill unmatched columns

Value

a single object of the same class as the first input, or of class matrix if the first object is one dimensional

Details

Similar to rbind.fill.matrix, but works for Matrix as well as all other R objects. It is completely agnostic to class, and will produce an object of the class of the first input (or of class matrix if the first object is one dimensional).

The implementation is recursive, so it can handle an arbitrary number of inputs, albeit inefficiently for large numbers of inputs.

This method is still experimental, but should work in most cases. If the data sets consist solely of data frames, rbind.fill is preferred.

See Also

rbind.fill

rbind.fill.matrix

Examples

Run this code
df1 = data.frame(x = c(1,2,3), y = c(4,5,6))
rownames(df1) = c("a", "b", "c")
df2 = data.frame(x = c(7,8), z = c(9,10))
rownames(df2) = c("a", "d")
rBind.fill(df1,df2,fill=NA)
rBind.fill(as(df1,'Matrix'),df2,fill=0)
rBind.fill(as.matrix(df1),as(df2,'Matrix'),c(1,2),fill=0)
rBind.fill(c(1,2,3),list(4,5,6,7))
rBind.fill(df1,c(1,2,3,4))

m<-rsparsematrix(1000000,100,.001)
m2<-m
colnames(m)<-1:100
colnames(m2)<-3:102
system.time(b<-rBind.fill(m,m2))

Run the code above in your browser using DataLab