[R] quetion about matrix compute

JS Huang js.huang at protective.com
Fri Jan 30 18:52:56 CET 2015


Hi,

  Here is my implementation.  Hope this helps.

> b
[1] 1 2 3 4 5
> c
[1] 1 2 1 3 5 4
> sapply(b,function(x)ifelse(x==c,1,0))
     [,1] [,2] [,3] [,4] [,5]
[1,]    1    0    0    0    0
[2,]    0    1    0    0    0
[3,]    1    0    0    0    0
[4,]    0    0    1    0    0
[5,]    0    0    0    0    1
[6,]    0    0    0    1    0



--
View this message in context: http://r.789695.n4.nabble.com/quetion-about-matrix-compute-tp4702505p4702532.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list