How do I remove these missing values:
a = ["NY", "NY", "NY", missing, missing]
How do I remove these missing values:
a = ["NY", "NY", "NY", missing, missing]
You can wrap it in an iterator that skips missing values:
skipmissing(a)
If you need to actually materialize that vector you can collect it:
collect(skipmissing(a))
You could also use filter
:
filter(!ismissing, a) # this copies the data into a new vector
# or
filter!(!ismissing, a) # this modifies the vector a in-place.
What are the disadvantages of the Matlab-style (?) solution: a[.~ismissing.(a)]
?
Thanks.
It allocates, while skipmissing
does not.
Also seems harder to read.
It actually allocates two arrays, first a BitVector for indexing, and then the output vector.
Also, ~
is bitwise not, and while that works well on a BitVector
, it seems risky and implementation-dependent. a[.!ismissing.(a)]
seems more semantically correct.
Edit: My spellchecker always replaces ismissing
with dismissing
. Happens all the time, suddenly.