Skip to content
Prev 131202 / 398502 Next

reduce the code used by "for"

> y=array(rep(x,15),c(5,3,2))
 > dimnames(y)=list(1:5,letters[1:3],NULL)

So to have in the workspace:
 > y
, , 1
   a  b  c
1 10 50 40
2 20 10 50
3 NA 20 10
4 30 NA 20
5 40 30 NA

, , 2
   a  b  c
1 30 NA 20
2 40 30 NA
3 50 40 30
4 10 50 40
5 20 10 50

Then to set the missing in the third row to 0:
 > y[3,,][which(is.na(y[3,,]))]=0

and to set the missing in the other rows to 1:
 > y[-3,,][which(is.na(y[-3,,]))]=1

domenico vistocco
Luis Ridao Cruz wrote: