Created
May 7, 2024 15:09
-
-
Save njudd/849f3bb47a1acd5ebe36f8e06d10d63b to your computer and use it in GitHub Desktop.
R data table standardize a set of cols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pacman::p_load(data.table, stringr) | |
setDT(ct) | |
col_fence.s <- c("col1", "col2", "col3") | |
ct[,(str_c(col_fence.s, ".s")) := lapply(.SD, function(x) as.numeric(scale(x))), .SDcols=col_fence.s] # making new ones with a .s suffex |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment