Re: [R] assignment of matrix

From: Uwe Ligges <ligges_at_statistik.uni-dortmund.de>
Date: Mon 25 Jul 2005 - 21:44:49 EST

wrote:

> Hi,
> I have created a matrix and initially all elements in the matrix was
> assigned to NA.Then I want to assign values to some elements of this
> matrix. Can I use formation like matrix[i][j] <- 4?if not, how can i do
> this? now I have three vectors
> y1 y2 y3
> 3 4 3.1
> 5 2 4.2
> if I want to assign y3's value to matrix, where the value's row and
> column should correspond the y1's and y2's value, such like
> matrix[y1[1]][y2[1]] <- y3[1]

For a matrix X:

 X[cbind(y1, y2)] <- y3

Uwe Ligges

> how can this be realized?
> thanks
> Hao Wu
>
>
> ------------------------------------------------------------------------
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Mon Jul 25 21:47:52 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:34:01 EST