defaults to convert all character columns except named 'C' to numeric useful for nonmem ready datasets with `.` for missing values
char_to_numeric(df, exclude_cols = "C")
df | dataframe to convert character columns to numeric |
---|---|
exclude_cols | vector of column names to be skipped from conversion |
dataframe
nm_dat <- data.frame(C = c('.', '.'), DV = c("1", "2"), stringsAsFactors = FALSE) char_to_numeric(nm_dat)#>#>#> C DV #> 1 . 1 #> 2 . 2# if 'C' col is 0/1 rather than typical 'C' or '.' char_to_numeric(nm_dat, exclude_cols = NULL)#>#>#> C DV #> 1 NA 1 #> 2 NA 2