Drop rows of an array containing missing values

Hi guys,

I want to drop rows containing missing values in an array. I can do this by converting the array to a df, and then using the skipmissing function from DataFrames.jl but I prefer to operate on an array rather than doing anything in the data frame to reduce memory consumption. CMIIW

function drop_missing(A::AbstractArray)
    ncol = size(A,2)
    a = []
    for i in eachrow(A)
        if sum(ismissing.(i))==0
        a = vcat(a,i)
        else
        end
    end
    return permutedims(reshape(a, (ncol, :)))
end

X = ["Alex" "A" 28; "Bond" "A" missing;
    "Anna" "B" 25; "cyntia" "B" 27;
    "Clara" "A" 22; "Danny" "B" 24]

drop_missing(X) # 5x3 matrix, excluding the second one

is there a better way to do this?? may be a more efficient way. plus how to inplace the original array?

I’m on the phone so can’t check but I’d probably write something like

A[.!(any.(ismissing, eachrow(A)), :]
3 Likes

Thank you, it works. just need to add an additional “)”.

1 Like