Skip to content
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

Feature request: skipmissing keyword #61

Open
PharmCat opened this issue Dec 16, 2024 · 1 comment
Open

Feature request: skipmissing keyword #61

PharmCat opened this issue Dec 16, 2024 · 1 comment

Comments

@PharmCat
Copy link

Now it's hard to implement skipmissing

listingtable(
    df,
    :Conc => "Concentration (ng/mL)",
    rows = [:Formulation => "Formulation", :Subject => "ID"],
    cols = :Time => "Time (hr)",
    summarize_rows = :Formulation => [length => "N", 
    Pair(x->mean(skipmissing(x)), "Mean"), 
    Pair(x->std(skipmissing(x)),"SD"), 
    Pair(x->median(skipmissing(x)) , "Median"), 
    Pair(x->maximum(skipmissing(x)) , "Maximum"), 
    Pair(x->minimum(skipmissing(x)) , "Minimum")]
)

also it lead to error when only missing data found in group.

@jkrumbiegel
Copy link
Collaborator

You can use f ∘ skipmissing (written \circ + tab) for a short version of what you're doing, but if you want robustness against all-missing data, you can define a helper function like

function robust_skipmissing(f)
    return function(vec)
        all(ismissing, vec) && return Annotated("NC", "NC - Not computable", label = nothing)
        return (f  skipmissing)(vec)
    end
end

data = DataFrame(
    concentration = [missing, 4.5, 2.0, 1.5, 0.1, missing, 3.2, 1.8, 1.2, 0.2],
    id = repeat([1, 2], inner = 5),
    time = repeat([0, 0.5, 1, 2, 3], 2)
)

listingtable(
    data,
    :concentration => "Concentration (ng/mL)",
    rows = :id,
    cols = :time => "Time (hr)",
    summarize_rows = [
        length => "N",
        robust_skipmissing(mean) => "Mean", 
        robust_skipmissing(std) => "SD", 
        robust_skipmissing(median) => "Median", 
        robust_skipmissing(maximum) => "Maximum", 
        robust_skipmissing(minimum) => "Minimum",
    ]
)
Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants