We can do this with na.locf
from zoo
library(zoo)
na.locf(na.locf(df1), fromLast = TRUE)
# Col1 Col2
#1 20 10
#2 25 10
#3 15 10
#4 15 10
#5 15 15
More Related Contents:
- Summarizing multiple columns with dplyr? [duplicate]
- Relative frequencies / proportions with dplyr
- Split a large dataframe into a list of data frames based on common value in column
- Save a plot in an object
- How to cbind or rbind different lengths vectors without repeating the elements of the shorter vectors?
- lapply vs for loop – Performance R
- Select equivalent rows [A-B & B-A] [duplicate]
- YAML current date in rmarkdown
- Convert UNIX epoch to Date object
- Create new variables with mutate_at while keeping the original ones
- R: use magrittr pipe operator in self written package
- How to interpret dplyr message `summarise()` regrouping output by ‘x’ (override with `.groups` argument)?
- How to index a vector sequence within a vector sequence
- Cumulative count of each value [duplicate]
- Counting number of instances of a condition per row R [duplicate]
- Find value corresponding to maximum in other column [duplicate]
- Split delimited single value character vector
- R: Convert delimited string into variables
- Create a numeric vector with names in one statement?
- R split numeric vector at position
- Creating a Plot Window of a Particular Size
- R: invalid multibyte string [duplicate]
- Reordering factor gives different results, depending on which packages are loaded
- Join two data frames in R based on closest timestamp
- Raw text strings for file paths in R
- R – how to make barplot plot zeros for missing values over the data range?
- Specify height and width of ggplot graph in Rmarkdown knitr output
- how to debug “factor has new levels” error for linear model and prediction [duplicate]
- How to get all possible subsets of a character vector in R?
- Convert latitude and longitude coordinates to country name in R