Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monks,
I have two arrays. I want to delete all elements in Array 2 that are not in Array 1. On top of that delete elements from Array 3 with the same index as those deleted in Array 2. This is very easy but the problem lies in speed. In R I can do it in seconds whereas if I do it in normal loop way in perl it will take ages. Is there a method to match R speed in this operation? Short example below;
@Array_1 = ("a1","a2","a3","a4","a5","a6"); @Array_2 = ("a1","b2","c3","a4","f5","a6"); @Array_3 = ("1","2","3","4","5","6"); output @Array_2 = ("a1","a4","a6"); @Array_3 = ("1","4","6");
If I am doing operation on very large arrays is there a faster method than doing loops (I usually used foreach)? Thanks for sharing your wisdom.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Match speed of R in array procesing
by choroba (Cardinal) on Mar 28, 2012 at 15:38 UTC | |
|
Re: Match speed of R in array procesing
by BrowserUk (Patriarch) on Mar 28, 2012 at 16:34 UTC | |
by Anonymous Monk on Mar 28, 2012 at 17:41 UTC | |
|
Re: Match speed of R in array procesing
by tobyink (Canon) on Mar 28, 2012 at 16:00 UTC | |
|
Re: Match speed of R in array procesing
by davido (Cardinal) on Mar 28, 2012 at 16:21 UTC | |
|
Re: Match speed of R in array procesing
by moritz (Cardinal) on Mar 28, 2012 at 15:22 UTC | |
by Anonymous Monk on Mar 28, 2012 at 15:40 UTC | |
by moritz (Cardinal) on Mar 28, 2012 at 16:08 UTC |