1.4 In-Class Exercises

In this week’s practical, we’ll go a little further into what’s possible with R. Don’t worry if you cannot remember everything in these primers—they’re only meant to familiarize you with what is possible and to get you some experience interacting with R and RStudio.

You can access the In-Class Exercises via the following link.


Recap

Hopefully, after completing the practical exercises for this week, you feel more comfortable using R’s basic functionality.

Here’s a brief description of the functions covered in this week’s practical exercises:

  • install.packages() for installing packages
    • Remember to put the package names in quotes
  • library() for loading packages
  • View() for viewing your dataset
  • select() for picking only certain columns
  • filter() for picking only certain rows
  • arrange() for changing the rows order
  • %>% aka “the pipe” for chaining commands together
    • In RStudio, you can hit ctrl+shift+m as a handy key combination
  • ? for help files

Logical tests and Boolean operators

  • == equal to
  • != not equal to
  • < less than
  • <= less than or equal to
  • > greater than
  • >= greater than or equal to
  • is.na() is the value NA (not available)
  • !is.na is the value not NA
  • & and (true only if the left and right are both true)
  • | or (true if either the left or right are true)
  • ! not (invert true/false)
  • %in% in (is left in the larger set of right values)
  • any() any (true if any in the set are true)
  • all() all (true if all in the set are true)
  • xor() xor (true if one and only one of the set are true)

ggplot2

  • ggplot() create the basic object from which to building a plot
  • aes() contains the aesthetic mappings (like x and y)
  • geom_bar() bar plots for distributions of categorical variables
  • geom_point() scatterplots for plotting two continuous variables
  • geom_label_repel() for plotting text
  • facet_wrap() for creating sets of conditional plots

End of In-Class Exercises