Skip to content

Instantly share code, notes, and snippets.

@jirilukavsky
Last active October 17, 2016 16:58
Show Gist options
  • Save jirilukavsky/ff17fa1086f3187a3f2fae99245a589d to your computer and use it in GitHub Desktop.
Save jirilukavsky/ff17fa1086f3187a3f2fae99245a589d to your computer and use it in GitHub Desktop.
Useful functions for R
# dplyr ====================
# descriptive stats per group, some columns omitted
selvars <- c(2, 3, 4, 5, 8, 9, 13)
d %>% do(describe(.[["varname"]])[, selvars])
# ggplot2 ==================
# set default theme to bw
theme_set(theme_bw())
# other ====================
# export to clipboard
cb <- function(data, echo=F, rownames=F) {
clipb <- pipe("pbcopy", "w")
write.table(data, file=clipb, row.names=rownames, dec=",", sep="\t")
close(clipb)
if (echo) return(data)
}
# rmarkdown
# current date in reports (by @fidadoma)
date: '`r format(Sys.time(), "%d %B, %Y")`'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment