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!