R Cheat Sheet

Categories: r

Exploring with Data

  • str - The structure of the data frame
  • head - The first six rows of the data frame
  • tail - The last six rows of the data frame
  • View - View the data frame in a spreasheet view
  • dim - Dimensions of the data frame
  • nrow - Number of rows in the data frame
  • ncol - Number of columns in the data frame
  • subset - Subset a data frame or vector

Descriptive Statistics

  • mean - Mean (or average)
  • sd - Standard deviation
  • median - Median
  • IQR - Inter-quartile range
  • table - Contingency table
  • prop.table - Proportional table (note takes the results of table as a parameter)
  • psych::describe - Common descriptive statistics
  • psych::describeBy - Common descriptive statistics by a grouping (qualitative) variable
  • cor - Correlation

Plots

  • Data ggplot(myDataFrame, aes(x=x, y=y)
  • Layers geom_point(), geom_histogram(), geom_bar(), geom_boxplot(), geom_text()
  • Facets facet_wrap(~ cut), facet_grid(~ cut)
  • Scales scale_y_log10()
  • Other options ggtitle('my title'), ylim(c(0, 10000)), xlab('x-axis label')