cbind(..., deparse.level=1) rbind(..., deparse.level=1)
Vector arguments are treated as row vectors by rbind and column vectors by cbind. If all arguments are vectors, the result will contain as many rows or columns as the length of the longest vector. Shorter vectors will be repeated.
The dimnames attribute of the returned matrix is constructed as follows: for any matrix argument, its dimnames attribute is carried over; for any vector argument with a names attribute, the names attribute becomes the row (column) component of dimnames for cbind (rbind); any vector argument may be given in name=value form, where the name specifies its corresponding dimnames entry. If cbind is given more than one named vector or matrix, the rownames of the result are the names of the last named vector or matrix with rownames in the argument list (and similarly for the column names the result of rbind).
If arguments are time series, no attempt is made to relate their time parameters. See ts.union and ts.intersect for this case. Arguments that are NULL or zero-length are ignored.
A better way to do the same thing is to create a matrix which is the final size before entering the for loop: x <- matrix(nrow=n, ncol=p) Then use replacement inside the for loop: x[,i] <- tmp.vec This latter strategy uses much less memory than the method using cbind. The "cbind" method should only be used when the eventual size of the matrix is unknown.
# add column of ones cbind(1, xmatr) %*% regr$coef# add 2 new rows rbind(matrix, newrow1, newrow2)
# 3 column matrix with column dimnames cbind(gnp=gnp, income=income, unemployment=unemployment)
#4 combining two named vectors mil1 <- c(c=3,d=4,e=5) mil2 <- c(f=6,g=7,h=8) cbind(mil1, mil2) #columnames will be mil1, mil2 #rownames will be f g h