Hi:

Check the class and dimensions of your objects. If mat1 is either
an eight element numeric vector or a one-row matrix, you should
have no problem:

> mat1 <- 1:8         # vector
> mat2 <- matrix(rnorm(240), nrow =30)
> class(mat1)
[1] "integer"
> class(mat2)
[1] "matrix"
> mat3 <- mat2
> mat3[1, ] <- mat1
> head(mat3, n = 3)
           [,1]       [,2]       [,3]       [,4]      [,5]       [,6]
[1,] 1.00000000  2.0000000  3.0000000  4.0000000 5.0000000  6.0000000
[2,] 0.07651876 -0.8993153 -0.2798143 -0.1728898 0.2953603 -0.2125125
[3,] 0.12433595  0.6025504  0.1784886  0.2304723 0.8189139  1.7240880
            [,7]       [,8]
[1,]  7.00000000  8.0000000
[2,] -0.08513052 -0.5989580
[3,] -1.78079197 -0.5740252
> class(mat3)
[1] "matrix"                         # check

> mat1a <- matrix(1:8, nrow = 1)  # one row matrix
> class(mat1a)
[1] "matrix"
> dim(mat1a)
[1] 1 8
> mat2[1, ] <- mat1
> class(mat2)
[1] "matrix"
> dim(mat2)
[1] 30  8
> head(mat2, n = 3)
           [,1]       [,2]       [,3]       [,4]      [,5]       [,6]
[1,] 1.00000000  2.0000000  3.0000000  4.0000000 5.0000000  6.0000000
[2,] 0.07651876 -0.8993153 -0.2798143 -0.1728898 0.2953603 -0.2125125
[3,] 0.12433595  0.6025504  0.1784886  0.2304723 0.8189139  1.7240880
            [,7]       [,8]
[1,]  7.00000000  8.0000000
[2,] -0.08513052 -0.5989580
[3,] -1.78079197 -0.5740252     # check

It's entirely possible that either your mat1 is not a one-row numeric matrix
or your mat2 is not a matrix. Check the class, dimensions, etc.

HTH,
Dennis

On Fri, Jan 29, 2010 at 12:55 PM, anna <lippelann...@hotmail.com> 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...
>
> -----
> Anna Lippel
> --
> View this message in context:
> http://n4.nabble.com/Simple-question-on-replace-a-matrix-row-tp1427857p1427857.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to