Resources

How can I extract specific rows based upon a logical expression?

0

If I have a matrix of observations, how can I create a new matrix that contains only the rows in which the   first element in the  row is greater than 0?

Tags: asked October 8, 2012
aptech
352

1 Answer

0
accepted

The GAUSS function selif will extract rows from a matrix that match a logical expression. For example:

x = { 1 3,
     -2 4,
      2 1,
      7 -9 };

mask = x[.,1] .> 0;
xout = selif(x, mask);

After the code above the variables will have the following values:

x = 
       1        3 
      -2        4 
       2        1 
       7       -9 
mask = 
       1 
       0 
       1 
       1 
xout = 
       1        3 
       2        1 
       7       -9
aptech
352