Re: [R] Re place values matrix

From: Greg Snow <Greg.Snow_at_imail.org>
Date: Tue, 18 Nov 2008 09:33:48 -0700

Try something along these lines:

> mat <- matrix(0, 10, 10)
> x <- c(1,10,10,1)
> y <- c(1,1,10,10)
> z <- 1:4
> mat[ cbind(x,y) ] <- z
> mat

Hope this helps,

--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow_at_imail.org
801.408.8111



> -----Original Message-----
> From: r-help-bounces_at_r-project.org [mailto:r-help-bounces_at_r-
> project.org] On Behalf Of start
> Sent: Tuesday, November 18, 2008 8:55 AM
> To: r-help_at_r-project.org
> Subject: [R] Re place values matrix
>
>
> To replace particular values in a matrix we can use the following
> command.
>
> matrix[x,y] = value
>
> But what to do if I have a list of +- 1,000,000 values and associated
> x,y
> values.
> Is there an efficient way to replace my matrix with those values.
>
> My first idea was to replace x, y and values by vectors.......but that
> doesn't work.
> Value in this case can't be a vector :(. It results in a wrong
> replacement.
> It takes the last value of the matrix.........
>
>
> --
> View this message in context: http://www.nabble.com/Replace-values-
> matrix-tp20562113p20562113.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help_at_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.
______________________________________________ R-help_at_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.
Received on Tue 18 Nov 2008 - 16:38:15 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 18 Nov 2008 - 17:30:25 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive