R Bootcamp - Day 1

R & RStudio overview

Author

Jay Hesselberth

Published

October 21, 2024

RStudio - Exercise 1

  • We are using RStudio through Posit Cloud for the class.
  • Look at RStudio panels one at a time.
  • Environment, History, Console, Files, Plots, Packages, Help, etc.

See menu:

Help > Cheat Sheets > RStudio IDE Cheat Sheet

R as a calculator - Exercise 2

  • R can function like an advanced calculator

Try simple math.

Assign a numeric value to an object.

  • <- and = are assignment operators.
  • By convention, R programmers use <-.
  • x <- 1 reads “set the value of x to 1”.

. . .

= and == are two different operators.

  • a = is used for assignment (e.g., x = 1)

  • a == tests for equivalence (e.g. x == 1 says “does x equal 1?”)

Functions and arguments - Exercise 3

Writing a simple function - Exercise 4

Data types - Exercise 5

  • There are many data types in R.
  • We’ll mainly use numeric, character, and logical.

Vectors - Exercise 6

Let’s create some vectors.

  • The c function combines values together (e.g., c(1,2,3))

. . .

Data frames

  • A data.frame is a rectangle, where each column is a vector, and each row is a slice across vectors.

  • data.frame columns are vectors, and can have different types (numeric, character, factor, etc.).

  • A data.frame is constructed with data.frame().

Data frames & tibbles - Exercise 7

Create a data.frame and tibble.

Now echo the contents of df and tbl to the console and inspect

R packages - Exercise 8

Let’s do the following to explore R packages:

  • Look at the “Environment” panel in Rstudio
  • Explore Global Environment
  • Explore the contents of a package

Quarto Exercise - Exercise 9

Let’s do the following to explore Quarto documents:

  • Create a new Quarto document
  • Render the document to see the output

Problem sets and submission

Your first problem set is in problem-sets/ps-01.qmd