I have a dataframe with zeros and missing values and I would like to create an indicator array that assigns a one if the value is zero and a zero otherwise. I would like missing values to be included in this otherwise statement, meaning they should be assigned a zero too as they are not zero. I am unsure how to achieve this.
# Input
df = DataFrame(a = [0.0, missing, 3.0], b = [4.0, 5.0, 0.0])
# What I'm doing
not_zeros = .!iszero.(Matrix(df))
zeros = iszero.(Matrix(df))
# Desired Output
not_zeros2 = [0, 1, 1 ; 1, 1, 0]
zeros2 = [1, 0, 0 ; 0, 0, 1]
4 posts - 3 participants