-
Notifications
You must be signed in to change notification settings - Fork 194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
zscore with missing values #898
Comments
This seems like a nice use for my stalled `spreadmissings PR. |
Currently, # like zscore() but no type restrictions:
julia> function myzscore(x)
μ, σ = mean_and_std(x)
map(x -> (x - μ) / σ, x)
end
julia> a = [1, 2, missing, 3]
julia> using Accessors
julia> @modify(myzscore, skipmissing(a))
4-element Vector{Union{Missing, Float64}}:
-1.0
0.0
missing
1.0 It reads like "modify
Bonus: not only julia> a = [1, 2, NaN, 3]
julia> using Skipper
julia> @modify(myzscore, a |> skip(isnan))
4-element Vector{Float64}:
-1.0
0.0
NaN
1.0 |
If I wanted col means of dataframe with missings, I could do |
Yes that's typically a case that |
Thanks to composability of tbl = StructArray(a=[1, 2, missing, 3], b=[1, missing, 1, 2])
@modify(myzscore, StructArrays.components(tbl) |> Elements() |> skipmissing) If there's interest, it can be generalized to Tables interface, and more table types encouraged to support it, so that one would write @modify(myzscore, columns(tbl) |> Elements() |> skipmissing) and it worked for any table. Still, this is mostly just to show how powerful existing composable interfaces are in Julia, not to detract anyone from implementing |
@nalimilan do you think we could make
zscore
work with vectors containing missing values? The issue is that usingskipmissing
is problematic in this context.The text was updated successfully, but these errors were encountered: