[R] changing the values in a list

dxc13 dxc13 at health.state.ny.us
Fri Jan 11 04:38:46 CET 2008


useR's,

Does anyone know of an efficient way to change the values in a list to
different numbers stored in an object?  For example, consider the following:

y <- matrix(c(20, 13, 25, 10, 17), ncol = 1)

> res
[[1]]
      [,1]  [,2]  [,3]  [,4] [,5]  [,6]  [,7] [,8]  [,9] [,10] [,11] [,12]
[,13] [,14]
[1,]   NA   NA   NA 1.25 0.25 0.75   NA   NA   NA    NA    NA    NA  1.25 
0.25
[2,] 1.25 0.25 0.75   NA   NA   NA   NA   NA   NA  1.25  0.25  0.75    NA   
NA
[3,]   NA   NA   NA   NA   NA   NA 1.25 0.25 0.75    NA    NA    NA    NA   
NA
[4,]   NA   NA 1.25 0.25 0.75   NA   NA   NA   NA    NA    NA  1.25  0.25 
0.75
[5,]   NA   NA   NA   NA   NA 1.25 0.25 0.75   NA    NA    NA    NA    NA   
NA

[[2]]
       [,1] [,2]  [,3] [,4]  [,5]  [,6] [,7]  [,8]  [,9] [,10] [,11] [,12]
[,13] [,14]
[1,]   NA   NA   NA   NA   NA   NA   NA   NA   NA    NA    NA    NA    NA   
NA
[2,]   NA   NA   NA   NA   NA   NA   NA   NA   NA    NA    NA    NA    NA   
NA
[3,] 1.25 1.25 1.25 1.25 1.25 1.25 1.25 1.25 1.25  0.25  0.25  0.25  0.25 
0.25
[4,]   NA   NA   NA   NA   NA   NA   NA   NA   NA    NA    NA    NA    NA   
NA
[5,]   NA   NA   NA   NA   NA   NA   NA   NA   NA    NA    NA    NA    NA   
NA

What I want to do is change the values in each column of the list that are
not NA to their corresponding Y values in the matrix given.  So any real
number in the first position of any column in the list should be changed to
20, the second number would be changed to 13, and so on...
Does anyone know an easy way to do this?
Thanks in advance.

Derek
-- 
View this message in context: http://www.nabble.com/changing-the-values-in-a-list-tp14749183p14749183.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list