Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • subset of complement rows

    Sorry for the inelegant title -- Suppose I have a matrix of 100 rows, E(1..100). I can create a vector A=(21..30) and then extract a submatrix of rows, E[A,.]. That will comprise 9 rows. Then is there a straightforward way to extract a submatrix of rows not identified in A? It would comprise 91rows. Some command akin to E["not A",.]

  • #2
    I don't think you can do it with subscripts, but select() can help:

    Code:
    keep = J(rows(E), 1, 1)      
    keep[A] = J(length(A), 1, 0) 
    select(E, keep)
    The vector -keep- has 1 for rows to keep (initially all) and 0 for rows to drop (obtained from vector A), and -select- does the work. No loops.

    Comment


    • #3
      I'm not aware of any one-liner that does that, but you could use the select() function:

      Code:
      // First create the E and A objects:
      E = J(5, 1, 1..5) + J(1, 5, 10 :* (1::5) )
      A = 2 \ 3
      // Note that A is a column vector (not a row vector as in your example)
      
      //Then select the sample:
      idx = J(rows(E), 1, 1)
      idx[A] = J(rows(A), 1, 0)
      select(E, idx)
      Edit: just saw German's response; it's exactly the same so I'm guessing this trick is the accepted best practice!

      Comment

      Working...
      X