[R] Simple question on replace a matrix row

David Winsemius dwinsemius at comcast.net
Fri Jan 29 22:07:06 CET 2010


On Jan 29, 2010, at 3:55 PM, anna wrote:

>
> Hello, I have a matrix mat1 of dim [1,8] and mat2 of dim[30,8], I  
> want to
> replace the first row of mat2 with mat1, this is what I do:
> mat2[1,]<-mat1 but it transforms mat2 in a list I don't understand,  
> I want
> it to stay a matrix...
>
What makes you think mat1 was a matrix to begin with?

 > mat1 <- matrix(8:1, 1,8)
 > mat2 <-matrix(1:(8*8), 8,8)

 > mat2[1,] <- mat1
 > mat2  # an 8 x 8 matrix

We cannot tell what sort of errors you are making (since your provided  
no reproducible example), but you surely are making errors.

David Winsemius, MD
Heritage Laboratories
West Hartford, CT



More information about the R-help mailing list