Skip to content

Instantly share code, notes, and snippets.

@njudd
Created May 7, 2024 15:09
Show Gist options
  • Save njudd/849f3bb47a1acd5ebe36f8e06d10d63b to your computer and use it in GitHub Desktop.
Save njudd/849f3bb47a1acd5ebe36f8e06d10d63b to your computer and use it in GitHub Desktop.
R data table standardize a set of cols
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