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 [[alternative HTML version deleted]]
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 > ErezMaybe 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 ------------------------------
Dear Erez, How about C <- A + B ? Regards, John -------------------------------- John Fox Department of Sociology McMaster University Hamilton, Ontario Canada L8S 4M4 905-525-9140x23604 http://socserv.mcmaster.ca/jfox --------------------------------> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Erez > Sent: Tuesday, November 01, 2005 5:39 AM > To: r-help at stat.math.ethz.ch > Subject: [R] (no subject) > > 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 > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html
On Tue, 2005-11-01 at 12:39 +0200, 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 >[I did not see a reply to this. The date indicates that it was sent on Tuesday, but I just got it today] Please use an informative subject. What's wrong with just adding the two vectors, if the rules are as simple as you indicate?> A[1] 0 1 0 0 1 1 0 0> B[1] 0 0 0 1 0 1 1 1> C <- A + B> C[1] 0 1 0 1 1 2 1 1 HTH, Marc Schwartz