I had the following code to change all columns starting with "DT" to Date
format with mutate_at
from dplyr
date_cols <- str_subset(names(df),'^DT')
df <- df %>%
mutate_at(
.vars= date_cols,
.funs=list(~ as.Date(.,format = "%d%m%Y"))
)
To do the same thing using data.table I wrote the following code (which works)
date_cols <- str_subset(names(df),'^DT')
for (column in date_cols) {
df[,(column) := as.Date(df[[..column]],format = "%d%m%Y")]
}
The question is if there isn't a mutate_at
equivalent in data.table
which would avoid the explicit for
loop? (Not really a problem, just curiosity)