Checks if check_cols exist in dt and are of type is_fun. If any of check_cols are of that type, then modifies the values using as_fun.

change_col_type(dt, check_cols, is_fun = is.integer, as_fun = as.numeric)

Arguments

dt

[data.table()]

check_cols

[character()]
name of columns in dt to check and modify.

is_fun

[function()]
function like is.integer(), is.character() etc. to check if each of check_cols values evaluate to true. Default is is.integer().

as_fun

[function()]
function like as.integer(), as.character() etc. to change column values to. Default is as.numeric().

Value

Modifies dt in place and returns dt invisibly.

Examples

dt <- data.table::data.table(year = 1950L, age_start = 0L) change_col_type(dt, c("year", "year_start", "age_start"))