[R] re placing values in a matrix

From: dxc13 <dxc13_at_health.state.ny.us>
Date: Thu, 31 Jan 2008 19:03:51 -0800 (PST)

useR's,

Consider:
y <- c(20, 25, 30)
> m <- matrix(c(0.0,1,NA,0.5,1.25,0.75, 0.5, NA,
> NA),byrow=TRUE,nrow=3,ncol=3)
> m

     [,1] [,2] [,3]

[1,]  0.0 1.00   NA
[2,]  0.5 1.25 0.75
[3,]  0.5   NA   NA

For each numeric value, I want to replace them with their corresponding y-value. The result should look like (here, each row represents a variable rather than the columns):

      [,1] [,2] [,3]

[1,]  20   25   NA
[2,]  20   25   30
[3,]  20  NA   NA

Does anyone know how I can do this using apply()? Or is there an easier way? Thanks in advance.

Derek

-- 
View this message in context: http://www.nabble.com/replacing-values-in-a-matrix-tp15219764p15219764.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.
Received on Fri 01 Feb 2008 - 11:46:53 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 Fri 01 Feb 2008 - 12:30:10 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