Last active
August 19, 2025 13:04
-
-
Save njudd/849f3bb47a1acd5ebe36f8e06d10d63b to your computer and use it in GitHub Desktop.
R data table standardize a set of cols
This file contains hidden or 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(as.character(scale(x)))), .SDcols=col_fence.s] # making new ones with a .s suffex | |
| # super sketchy do to only as.numeric incase it is a factor!!! updated to as.numeric(as.character |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment