Converting all NaN's to Missing and vice-versa in relevant columns

I am experimenting with dataframes and missings, which have of course morphed over the last few months. my dataframes can have float columns that are already unions(missing), float columns that are not yet unions, and non-float columns. I would like to have a function that replaces all missings with NaNs in float-like columns, and vice-versa. by float-like I mean float16, float32, float64, float128 and their union-missing variants.

I believe I can code these functions myself, but I am wondering if there are standard dataframe functions that already exist and that I should recommend instead.

PS: for writing functions that operate on both AbstractFloat columns and on Union{Missing,AbstractFloat} columns (but not, say, Int or String columns), I think one can use eltype(col) <: Union{Missing,AbstractFloat}.

1 Like
coalesce.(column, NaN) # Missing => NaN
replace(column, NaN=>missing) # NaN => missing
7 Likes

thanks. the new replace is much more convenient than the old recode. but I presume that there are no dataframes versions of such functionalities, because we expect users to write them. correct?