[R] (no subject)
(Ted Harding)
Ted.Harding at nessie.mcc.ac.uk
Sat Nov 5 15:55:35 CET 2005
On 01-Nov-05 Erez wrote:
> Hi
>
> I need an advise if any one can help me.
> i have mass of data in 2 array A and B:
> A = 0 1 0 0 1 1 0 0
> B = 0 0 0 1 0 1 1 1
> and i have 3 rules to merge them into 3rd array C:
> if A[i] + B[i] == 0 then C[i]=0
> if A[i] + B[i] == 1 then C[i]=1
> if A[i] + B[i] == 2 then C[i]=2
> it looks easy but with the regular way (loop) with large data it takes
> days (i test it).
> If any one can advise me what to do i'll be happy.
>
> Thanks
> Erez
Maybe there is a hidden complication in your context, but if those
are the only possibilities (as you have stated it above), then
what is wrong with:
C = A + B
??
On the other hand, for instance, if C has values and you only want
to change those values as above for the relevant values of i, then
you could do
ix <- (A+B==0)|(A+B==1)|(A+B==2)
C[ix] <- A[ix] + B[ix]
or some similar possibility, depending on what you really want to do.
Best wishes,
Ted.
--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 05-Nov-05 Time: 14:55:33
------------------------------ XFMail ------------------------------
More information about the R-help
mailing list