[ADMB Users] extraction of array elements using selection logic
dave fournier
davef at otter-rsch.com
Mon Feb 25 11:23:59 PST 2013
> I'm looking for an ADMB form of R-style logical selection from arrays.
> Ignore if this should be regarded as just a C programming question and
> shouldn't be here.
>
> I currently use a bulky loop-based method to accomplish this, looking
> for something more efficient. For example say I have a matrix BEFORE of
> index and value columns and I want to remove rows with values of zero to
> obtain matrix AFTER. Anybody know how to do this in a few lines without
> looping?
>
> BEFORE AFTER
> 1 34.58641 1 34.58641
> 2 0 3 42.54367
> 3 42.54367 4 46.27856
> 4 46.27856 5 49.85982
> 5 49.85982 6 53.29379
> 6 53.29379 7 56.58652
> 7 56.58652 8 59.74382
> 8 59.74382 9 62.77126
> 9 62.77126 10 65.67418
> 10 65.67418
You could write a little function to do this.
If it is to be generic you need to tell it which column to use
something like
dmatrix N = not_equal(M,2,0.0);
More information about the Users
mailing list