I want to change the class of selected variables in a data table using a vectorized operation. I am new to data.table syntax and try to learn as much as possible. I am now a basic question, but it will help me better understand the way data is displayed!
A similar question was asked here ! However, the solution seems to relate to reclassifying only one column or all columns. My question is unique across multiple columns.
Create pseudo data data <- data.table(id = 1:10, height = rnorm(10, mean = 182, sd = 20), weight = rnorm(10, mean = 160, sd = 10), color = rep(c('blue', 'gold'), times = 5)) Search for columns to be reclassed index <- grep('(id)|(height)|(weight)', names(data)) Failed attempt to reclass columns used the data.table method data <- data[, lapply(index, as.character), with = F]
Any help would be greatly appreciated. My data is big, and so using regular expressions to create a vector of column numbers for reclassification is necessary.
Thank you for your time.
source share