Skip to content

Instantly share code, notes, and snippets.

@chris-b1
Last active May 27, 2020 12:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chris-b1/50fffa29bf03ab8a6e3925a35b1bab90 to your computer and use it in GitHub Desktop.
Save chris-b1/50fffa29bf03ab8a6e3925a35b1bab90 to your computer and use it in GitHub Desktop.
DataFrames.jl forward fill
ffill(a::AbstractArray) = copy(a)
function ffill(a::AbstractArray{Union{Missing, T}}) where {T}
res = similar(a, T)
if ismissing(first(a))
error("first value in array is missing")
else
fillval::T = first(a)
end
for i in eachindex(a)
v = a[i]
if !ismissing(v)
fillval = v
end
res[i] = fillval
end
res
end
@kbjarnason
Copy link

Would be great to extend to dataframes :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment