-
Notifications
You must be signed in to change notification settings - Fork 18
Open
Description
This is something I have discussed elsewhere as being useful, and came up today on slack.
Problem
function standardize(x)
mu = mean(x)
sigma = std(x)
return (x .- mu) ./ sigma
end
standardize([1,2,3, missing]
We can't use passmissing
because this isn't an element-wise operation. We need an operation that applies skipmissing to the input, then applies the function, then "spreads" the result of the function to a vector of the same length as the output.
function skipmissing_then_collect(fun, args...)
smargs = skipmissings(args...)
res = fun(smargs...)
out = Union{eltype(res), Missing}[missing for i in 1:length(first(args))]# assume all args vectors also
res_counter = 1
for i in eachindex(first(smargs))
out[i] = res[res_counter] # can probably do fancy iteration stuff here
res_counter += 1
end
out
end
This might solve a lot of problems in DataFrames as well.
Metadata
Metadata
Assignees
Labels
No labels