Last active
May 27, 2020 12:37
-
-
Save chris-b1/50fffa29bf03ab8a6e3925a35b1bab90 to your computer and use it in GitHub Desktop.
DataFrames.jl forward fill
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Would be great to extend to dataframes :)