rbind-ing numeric matrices
Hi Nick, We absolutely need a reproducible example, with code and data, to be able to help you. Because otherwise I can't replicate your problem:
A <- matrix(1:5, nrow=1, ncol=5) B <- matrix(6:20, nrow=3, ncol=5) C <- rbind(A, B) A
[,1] [,2] [,3] [,4] [,5] [1,] 1 2 3 4 5
B
[,1] [,2] [,3] [,4] [,5] [1,] 6 9 12 15 18 [2,] 7 10 13 16 19 [3,] 8 11 14 17 20
C
[,1] [,2] [,3] [,4] [,5] [1,] 1 2 3 4 5 [2,] 6 9 12 15 18 [3,] 7 10 13 16 19 [4,] 8 11 14 17 20 Sarah
On Tue, May 1, 2012 at 11:52 AM, Nick Switanek <nswitanek at gmail.com> wrote:
Good morning, I'm running into trouble rbind-ing numeric matrices with differing numbers of rows. In particular, there seem to be issues whenever a one-row numeric matrix is involved. Assume A is a numeric matrix with 1 row and Y columns and B is a numeric matrix with X rows and Y columns. Let C be the result of rbinding A and B. Then C is a numeric matrix with X + 1 rows and Y columns, only instead of the rows of B being "stacked" beneath the row of A as expected, the first Y elements of the 1st column of B are placed in the 2nd row of C, the remaining values of B are discarded, and NULL values fill out the rest of the matrix C. The number of columns of A and B match. The colnames of A and B match. Both are numeric matrices. I've pored over the rbind/cbind documentation but can't identify why I'm getting this behavior from rbind. I'd be extremely grateful for your suggestions or thoughts. Nick
Sarah Goslee http://www.functionaldiversity.org