As the following code shows, i want to forward fill missing values use Impute.locf function, but just within the same :id
using DataFramesMeta, Impute df = DataFrame(id = repeat(1:3, 2), value = [1,missing,3,4,missing,missing]) df = @chain df begin @by(:id, :value = Impute.locf(:value), $(:)) end # following code raises error too, so this doesn't seem to be DataFramesMeta's problem # combine(groupby(df, :id), :value => (x -> Impute.locf(x)))
Unexpectedly, it raises
ERROR: AssertionError: !(all(ismissing, data))
this is clearly beacause there are all missing value under the same :id=2, but the following code
df = DataFrame(id = repeat(1:3, 2), value = [missing,missing,missing,missing,missing,missing]) df = @chain df begin @transform(:value = Impute.locf(:value)) end
completed with no error. It just leaves all values missing, which is the desired result
Row │ id value │ Int64 Missing ─────┼──────────────── 1 │ 1 missing 2 │ 2 missing 3 │ 3 missing 4 │ 1 missing 5 │ 2 missing 6 │ 3 missing
My questions are:
- Is it a bug or a feature (for some concerns I don’t know)?
- How do I get the (grouped) results? Of course, the simpler the code, the better.
Thanks in advance!