[R] alternative to ifelse
S Ellison
S.Ellison at lgcgroup.com
Fri Jun 21 12:12:14 CEST 2013
Once you have this matrix:
mx <- cbind(x1, x2, x3, x4)
> > x1 x2 x3 x4
> > [1,] 22 14 24 10
> > [2,] 27 12 1 2
> > [3,] 23 13 6 2
> > [4,] 27 6 21 2
> > [5,] 14 29 12 19
> > [6,] 5 14 11 29
> > [7,] 10 10 27 25
> > [8,] 16 29 28 10
> > [9,] 22 22 19 7
> > [10,] 30 20 5 22
> > [11,] 2 12 24 15
> > [12,] 5 21 13 22
> > [13,] 23 17 28 3
> > [14,] 1 7 24 14
> > [15,] 12 15 8 8
ifelse( apply(mx, 1, function(x) any(x==1)), 1, 0 )
#or
as.numeric( apply(mx, 1, function(x) any(x==1)) )
should work.
S Ellison
*******************************************************************
This email and any attachments are confidential. Any use...{{dropped:8}}
More information about the R-help
mailing list