The dataset below has the characteristics of my large dataset. I manage it in data.table, some columns are loaded as chr, despite the fact that they are numbers, and I want to convert them to numeric and these column names are known
dt = data.table(A=LETTERS[1:10],B=letters[1:10],C=as.character(runif(10)),D = as.character(runif(10)))
I can convert these 2 columns to numeric using the code above, but I want to update dt. I tried using: = however this did not work. I need help here!
dt.out2 <- dt[, strTmp:=lapply(.SD, as.numeric, na.rm = T), .SDcols = strTmp]
I even tried the code below (encoded as data.frame - not my ideal solution, even if it works, as I am worried, in some cases the order may change), but it still does not work. Can anyone tell me why it is not working?
dt[,strTmp,with=F] <- dt[,lapply(.SD, as.numeric, na.rm = T), .SDcols = strTmp]
Thanks in advance!
r data.table
Lafayette
source share