EDS 221 Day 2 AM

Data types and 1d structures


August 11th, 2025

Review day 1: Code execution


What’s the value of x after you execute these commands?

What output would you see at the console?

x <- 10
x + 1
y <- x
y <- y * 2
x
y

Review day 1: Version control


Label the arrows in the following diagram with the corresponding git command.

Create a datasheet


Photo by Annabelle Lang/LSU College of Agriculture

Atomic types


There are four atomic types in R.

  • Character (text)
  • Double (decimal numbers)
  • Integer (round numbers)
  • Logical (true and false)

Atomic types are the basic building blocks of data structures in R.

Like the name implies, everything else is made out of them.

Coercion


Atomic vectors have to be one type. When you combine vectors of different types, one gets coerced into the other’s type.

From Hands on Programming with R

Making vectors


There are many ways to make vectors. Some of the most common are:

# Sequence operator
2:4
[1] 2 3 4
# c() function
c("Violet", "Cyan")
[1] "Violet" "Cyan"  
# Vector constructors
character(5)
[1] "" "" "" "" ""
double(5)
[1] 0 0 0 0 0
# Random number generators
rnorm(3, mean = 0, sd = 1)
[1] -1.1841031 -0.3077750 -0.3283373
rpois(4, lambda = 10)
[1]  5 11  6  8