[R] Matrix Manipulation

emj83 stp08emj at shef.ac.uk
Thu Nov 4 16:47:38 CET 2010


Hi,

Is there a quick way to go from this matrix:
> A
     [,1] [,2] [,3]
[1,]    1    1    1
[2,]    2    2    2
[3,]    3    3    3
[4,]    4    4    4
[5,]    5   NA    5
[6,]   NA   NA    6
[7,]   NA   NA   NA

to this matrix:
> B
     [,1] [,2] [,3]
[1,]    1   NA   NA
[2,]    2   NA    1
[3,]    3    1    2
[4,]    4    2    3
[5,]    5    3    4
[6,]   NA    4    5
[7,]   NA   NA    6

without using a loop? 
For example using a vector which describes how many NA's are required from
the "top" of the matrix- so in this case it would be c(0,2,1).

Many thanks Emma


-- 
View this message in context: http://r.789695.n4.nabble.com/Matrix-Manipulation-tp3027266p3027266.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list