R is a wonderfully confusing language. Fortunately, people like Hadley Wickham are here to help. Therefore, most of these commands will be in the context of packages like dplyr and ggplot.
If you are in need of some more general plotting advice, take a look at the Compendium of Clean Graphs in R.
Working with Strings
Sometimes you want to create a cartesian product of multiple lists of strings. Well friend, Sven Hohenstein has got you covered. In short, add the following function to your code:
combine2 <- function(..., prefix="", sep="") {
paste0(prefix, levels(interaction(..., sep=sep)))
}
Examples:
a <- c('a', 'b')
b <- c('1', '2', '3')
c <- c('??', '!!)
combine2(a, b)
#[1] "a1" "b1" "a2" "b2" "a3" "b3"
combine2(a, b, c)
#[1] "a1!!" "b1!!" "a2!!" "b2!!" "a3!!" "b3!!" "a1??" "b1??" "a2??" "b2??" "a3??" "b3??"
Dataframes
Use df %>% group_by(X) %>% tally for a nice quick summary of a dataframe.
Get number of rows in the dataframe: nrow(df).
Working With Files
Write delimited file without quotes, row, and column labels:
df %>% write.table('gtlds.txt', row.names=FALSE, col.names=FALSE, quote=FALSE)
Read a csv using the readr package: df <- read_csv('test.csv').
RStudio
Shortcut for the dplyr operator (%>%): Cmd+shft+m.
ggplot
Force commas in axis labels:
library(scales)
ggplot(df, aes(x=foo)) +
stat_ecdf() +
scale_x_continuous(labels=comma)
Quantiles
quantile(df$foo, probs=seq(0,1,0.25))