Say I have this df
df <- data.table(a = c('2022-01-20', '2022-01-21')
); df
a
1: 2022-01-20
2: 2022-01-21
Note that lubridate is able to convert this character column to date properly
fast_strptime(df$a, "%Y-%m-%d")
[1] "2022-01-20 UTC" "2022-01-21 UTC"
but when trying to store back to df data.table gives
df[, a := fast_strptime(a, "%Y-%m-%d") ]
Error in `[.data.table`(df, , `:=`(a, fast_strptime(a, "%Y-%m-%d"))) :
Supplied 9 items to be assigned to 2 items of column 'a'. If you wish to 'recycle' the RHS please use rep() to make this intent clear to readers of your code.
Looking forward to any ideas. Thank you.