Announcement

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

  • Remove blank lines from string colvector

    If I have a string colvector in Mata, how can I create a new string colvector that removes rows with empty lines?

  • #2
    Code:
    : a = ("dog" \ "" \ "cat")
    
    : a
             1
        +-------+
      1 |  dog  |
      2 |       |
      3 |  cat  |
        +-------+
    
    : b = a:!=""
    
    : b
           1
        +-----+
      1 |  1  |
      2 |  0  |
      3 |  1  |
        +-----+
    
    : select(a,b)
             1
        +-------+
      1 |  dog  |
      2 |  cat  |
        +-------+
    
    :

    Comment


    • #3
      Thank you! I ended up using
      Code:
      b = select(a, strlen(a))
      . Is this directly equivalent?

      Comment


      • #4
        Yes, for what you are doing. Post #2 demonstrates technique that can be generalized to other selections defined with a logical expression.

        Comment


        • #5
          Originally posted by Archibald Dunlop View Post
          Thank you! I ended up using
          Code:
          b = select(a, strlen(a))
          . Is this directly equivalent?
          At some level, it is probably a fraction of a (milli-)second slower to get the length of (all) strings (in the vector) than comparing against null string.

          Comment

          Working...
          X