Group Selection by Condition in DataFramesMeta.jl

I am looking to select groups that follow a condition using DataFramesMeta.jl.

Reference example in R that I am looking to reproduce:

df = data.table(id = c(rep(1, 10), rep(2, 10), rep(3, 10)),
                x1 = c(rep(NA, 10), rnorm(10), c(rnorm(5), rep(NA, 5))))
df[, if(any(! .SD, .(id)]
df[, if(all(! .SD, .(id)]

Thanks in advance!

Unfortunately currently this is not very easy and you have to write:

filter(:x1 => x-> any(!ismissing, x), groupby(df, :id)) |> DataFrame
filter(:x1 => x-> all(!ismissing, x), groupby(df, :id)) |> DataFrame

However, in the upcoming release of DataFrames.jl (after this PR is merged) you can write using DataFramesMeta.jl:

@chain df begin
    @subset(any(!ismissing, :x1))
@chain df begin
    @subset(all(!ismissing, :x1))
1 Like