Advertisement
Guest User

Untitled

a guest
Apr 17th, 2018
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 0.28 KB | None | 0 0
  1. library(data.table)
  2. dataGenFunc <- function() sample.int(3L, 1e5, TRUE)
  3. DT <- data.table(v1 = dataGenFunc(), v2 = dataGenFunc(), v3 = dataGenFunc())
  4. sampleDT <- rbindlist(lapply(split(DT, by = names(DT)), function(subDT){
  5.   subDT[sample.int(nrow(subDT), round(nrow(subDT)*2/3))]
  6. }))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement