3 min read

Introduction to R


Date: Thursday, January 25, 2018 Time: 9:00am - 12:00pm Location: Young Research Library, West Classroom Categories: R (programming language) Calendar: http://calendar.library.ucla.edu/event/3835760

This hands-on workshop will cover basic concepts and tools related to using R in the context of data analysis. Participants will be encouraged to help one another and to apply what they have learned to their own research problems. We’ll cover:

  • A basic introduction to R and RStudio
  • Visualizing your data with ggplot2, the most popular graphing package in R
  • Tidying and transforming data for analysis

You’ll come out of the course with a good foundation on the most important tools in R for working and communicating with data. This course is taught via the tidyverse - a higher level set of packages in R that intends to make it eaier to work with data. You will need to pick up some of the lower level details on R programming as you learn R. See the information below to continue your R education.


Class Materials

Basic programming concepts

  • Use the datacamp tutorials for an intro to basic programming concepts in R.

  • From the Introduction to R course complete the following chapters. As you work through the chapters, carefully note the important terms and what they are used for. We recommend you do so in a notebook that you can easily refer back to.

    • Chapter 1 Intro to basics:
      • Console pane: where you enter in commands
      • Objects: where values are saved, how to assign values to objects.
      • Data types: integers, doubles/numerics, logicals, characters.
    • Chapter 2 Vectors:
      • Vectors: a series of values.
    • Chapter 4 Factors:
      • Categorical data (as opposed to numerical data) are represented in R as factors.
    • Chapter 5 Data frames:
      • Data frames are analogous to rectangular spreadsheets: they are representations of datasets in R where the rows correspond observations and the columns correspond to variables that describe the observations. We will revisit this later in Section \@ref(nycflights13).
  • From the Intermediate R course complete the following chapters:

    • Chapter 1 Conditionals and Control Flow:
      • Testing for equality in R using == (and not = which is typically used for assignment). Ex: 2 + 1 == 3 compares 2 + 1 to 3 and is correct R syntax, while 2 + 1 = 3 is not and is incorrect R syntax.
      • Boolean algebra: TRUE/FALSE statements and mathematical operators such as < (less than), <= (less than or equal), and != (not equal to).
      • Logical operators: & representing “and”, | representing “or”. Ex: (2 + 1 == 3) & (2 + 1 == 4) returns FALSE while (2 + 1 == 3) | (2 + 1 == 4) returns TRUE.
    • Chapter 3 Functions:
      • Concept of functions: they take in inputs (called arguments) and return outputs.
      • You either manually specify a function’s arguments or use the function’s defaults.

Tips on learning to code

  • Learning to code/program is very much like learning a foreign language
  • It can be very daunting and frustrating at first.
  • Put in the effort and are not afraid to make mistakes, anybody can learn.