Here’s a slightly faster and more compact way of doing it (version 1.9.3+):
DT[, filled4 := DT[!is.na(value)][DT, value, roll = T]]
More Related Contents:
- Naming columns in a data table in R
- data.table objects assigned with := from within function not printed
- What is the purpose of setting a key in data.table?
- .EACHI in data.table?
- Use a value from the previous row in an R data.table calculation
- How to efficiently calculate distance between pair of coordinates using data.table :=
- Sample random rows within each group in a data.table
- Melt using patterns when variable names contain string information – avoid coercion to numeric
- Error: package or namespace load failed for ggplot2 and for data.table
- How to perform join over date ranges using data.table?
- Split text string in a data.table columns
- How to speed up subset by groups
- knitr gets tricked by data.table `:=` assignment
- Add multiple columns to R data.table in one function call?
- Extract a column from a data.table as a vector, by position
- data.table merge based on date ranges
- Reason behind speed of fread in data.table package in R
- data.table row-wise sum, mean, min, max like dplyr?
- := (pass by reference) operator in the data.table package modifies another data table object simultaneously
- Rowwise cumulative sum
- Using data.table i and j arguments in functions
- R data.table breaks in exported functions
- Applying a function to each row of a data.table
- Union of intersecting vectors in a list in R
- Empty factors in “by” data.table
- data.table is not handling integer64 in by statement
- When and why does “print” need two attempts to print a “data.table”? [duplicate]
- How to use data.table within functions and loops?
- What you can do with a data.frame that you can’t with a data.table?
- data.table: anonymous function in j