Skip to content

Instantly share code, notes, and snippets.

@vsbuffalo
Last active August 29, 2015 14:04
Show Gist options
  • Save vsbuffalo/fdc8e336abd666c48391 to your computer and use it in GitHub Desktop.
Save vsbuffalo/fdc8e336abd666c48391 to your computer and use it in GitHub Desktop.
# Factors are more memory efficient (if labels > few bytes), since redundant multi-byte
# labels are stored once in memory (as attributes), and integers keep the mapping. E.g.:
a = sample(paste0("chrom", c(1:22, "X", "Y")), 1e8, replace=TRUE)
object.size(a)
# 800001192 bytes
object.size(factor(a))
# 400001744 bytes
# For long character vectors of repeating values, this *really* pays off.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment