diff --git a/src/TidierData.jl b/src/TidierData.jl index ae0bdd0b..e9b9396c 100644 --- a/src/TidierData.jl +++ b/src/TidierData.jl @@ -15,7 +15,7 @@ using Reexport @reexport using ShiftedArrays: lag, lead export TidierData_set, across, desc, n, row_number, starts_with, ends_with, matches, if_else, case_when, ntile, - as_float, as_integer, as_string, @select, @transmute, @rename, @mutate, @summarize, @summarise, @filter, + as_float, as_integer, as_string, fill_na, @select, @transmute, @rename, @mutate, @summarize, @summarise, @filter, @group_by, @ungroup, @slice, @arrange, @distinct, @pull, @left_join, @right_join, @inner_join, @full_join, @pivot_wider, @pivot_longer, @bind_rows, @bind_cols, @clean_names, @count, @tally, @drop_na, @glimpse, @separate, @unite, @summary diff --git a/src/docstrings.jl b/src/docstrings.jl index 848be905..2b7e5950 100644 --- a/src/docstrings.jl +++ b/src/docstrings.jl @@ -2099,4 +2099,49 @@ julia> @chain df begin 2 │ C 11 12.0 13.0 12.6667 13.5 14 3 2 3 │ D 16 17.0 18.0 18.0 19.0 20 5 0 ``` -""" \ No newline at end of file +""" + +const = docstring_fill_na +""" + fill(column, method) + +Fills missing values in a given column of a DataFrame. This function uses either Last Observation Carried Forward (LOCF) or Next Observation Carried Backward (NOCB) methods based on the provided argument. + +# Arguments + +- `column`: Column that with missing values +- `method`: "nocb" or "locf" depending on the desired strategy. +```jldoctest + +julia> df = DataFrame(dt1=[missing, 0.2, missing, missing, 1, missing, 5, 6], dt2=[0.3, missing, missing, 3, missing, 5, 6,missing]) +8×2 DataFrame + Row │ dt1 dt2 + │ Float64? Float64? +─────┼────────────────────── + 1 │ missing 0.3 + 2 │ 0.2 missing + 3 │ missing missing + 4 │ missing 3.0 + 5 │ 1.0 missing + 6 │ missing 5.0 + 7 │ 5.0 6.0 + 8 │ 6.0 missing + +julia> @chain df begin + @mutate(dt1 = ~fill_na(dt1, "locf")) + @mutate(dt2 = ~fill_na(dt2, "nocb")) + end +8×2 DataFrame + Row │ dt1 dt2 + │ Float64? Float64? +─────┼────────────────────── + 1 │ missing 0.3 + 2 │ 0.2 3.0 + 3 │ 0.2 3.0 + 4 │ 0.2 3.0 + 5 │ 1.0 5.0 + 6 │ 1.0 5.0 + 7 │ 5.0 6.0 + 8 │ 6.0 missing +``` +"""