I am normalizing only a few columns. I am subsetting the columns by specifying a range of columns using .SDcols. I don't know how to name the columns that result from the operation. The names need to be the original names.
dtbl <- data.table("col1"=c(1,2,3), "col2"=c(4,5,6), "col3"=c(7,8,9), "coln"=c("A", "B", "C"))
cols <- c("col1", "col2", "col3")
dtbl[, (cols) := lapply(.SD, function(x) ((x-mn)/(mx-mn))), .SDcols = cols]
# mn and mx are some predefined values that I am using to normalise the columns.
I am instead trying the following
dtbl[, **original_names** := lapply(.SD, function(x) ((x-mn)/(mx-mn))), .SDcols = col1:col3]
It is not working obviously. I am not sure how to get back the names of the columns that are being operated upon.
Edit:
I want to avoid typing the columns names. In this example, there are only three names but in my data there are several. Hence, I would like to subset a range of columns instead.