Skip to content

Instantly share code, notes, and snippets.

@1beb
Last active October 17, 2016 04:35
Show Gist options
  • Save 1beb/183511b51d615751860204344a02c799 to your computer and use it in GitHub Desktop.
Save 1beb/183511b51d615751860204344a02c799 to your computer and use it in GitHub Desktop.
library(data.table)
size = 1e6
resample <- function(x,size = 1e6) sample(x,size,replace = TRUE)
text <- c("Canada","Peru","Australia","Angola","France","", NA_character_)
text2 <- c("Oh Canada.","Arriba Peru.","Australia?","Vive la France.")
numerics <- rnorm(1e6)
dt <- data.table(
id = as.character(1:1e6),
i1 = resample(c(as.character(c(0:5,NA)),"")), # sometimes just blank
i2 = resample(c(as.character(c(100:500,NA)))),
n1 = as.character(round(rnorm(1e6),3)),
t1 = resample(text),
t2 = resample(text2)
)
for(j in names(dt)) set(dt, j = j, value = type.convert(dt[[j]])
str(dt)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment