I have data wrangling script, where I just want to fill all NAs with the value above it. I used to do it this way:
library(data.table)
library(tidyfast)
col1 <- c("A", "B", "C", "D")
col2 <- c("X", NA, "Z", NA)
dt <- data.table(col1,
col2)
dt[, col2 := dt_fill(dt, col2, .direction = 'down')]
And this always worked, but now I get the error:
Error in `[.data.table`(dt, , `:=`(col2, dt_fill(dt, col2, .direction = "down"))) :
Supplied 2 items to be assigned to 4 items of column 'col2'. If you wish to 'recycle' the RHS please use rep() to make this intent clear to readers of your code.
data.tablehasnafill()which doesn't work for character vectors yet but you can work around that: