R data.table multi column coversion by names [duplicate]
This question already has an answer here: How to apply same function to every specified column in a data.table 6 answers Let DT be a data.table: DT<-data.table(V1=factor(1:10), V2=factor(1:10), ... V9=factor(1:10),) Is there a better/simpler method to do multicolumn factor conversion like this: DT[,`:=`( Vn1=as.numeric(V1), Vn2=as.numeric(V2), Vn3=as.numeric(V3), Vn4=as.numeric(V4), Vn5=as.numeric(V5), Vn6=as.numeric(V6), Vn7=as.numeric(V7), Vn8=as.numeric(V8), Vn9=as.numeric(V9) )] Column names are totally arbitrary. David Arenburg Yes, the most efficient would be probably to run set in a for