Basic Types

Integers

i <- 1 + 1
i
## [1] 2

Doubles

3.14
## [1] 3.14
pi
## [1] 3.141593

Character Strings

s <- "Hello, world!"
s
## [1] "Hello, world!"

Logical

b <- TRUE
b
## [1] TRUE

Additional Types

Vectors

v <- c("one", "two")
v
## [1] "one" "two"

Dates (Using lubridate)

library(lubridate)

birthdate <- ymd(20000207)
year(birthdate)
## [1] 2000
wday(birthdate, label = TRUE)
## [1] Mon
## Levels: Sun < Mon < Tue < Wed < Thu < Fri < Sat

Factors

data <- c("East", "West", "East", "North", "North", "East", "West", "South", "West", "East", "North")
data_factor <- factor(data)
typeof(data_factor)
## [1] "integer"

Dataframes & Tibbles

library(gapminder)

gapminder
## # A tibble: 1,704 × 6
##    country     continent  year lifeExp      pop gdpPercap
##    <fct>       <fct>     <int>   <dbl>    <int>     <dbl>
##  1 Afghanistan Asia       1952    28.8  8425333      779.
##  2 Afghanistan Asia       1957    30.3  9240934      821.
##  3 Afghanistan Asia       1962    32.0 10267083      853.
##  4 Afghanistan Asia       1967    34.0 11537966      836.
##  5 Afghanistan Asia       1972    36.1 13079460      740.
##  6 Afghanistan Asia       1977    38.4 14880372      786.
##  7 Afghanistan Asia       1982    39.9 12881816      978.
##  8 Afghanistan Asia       1987    40.8 13867957      852.
##  9 Afghanistan Asia       1992    41.7 16317921      649.
## 10 Afghanistan Asia       1997    41.8 22227415      635.
## # … with 1,694 more rows
typeof(gapminder$continent)
## [1] "integer"
class(gapminder$continent)
## [1] "factor"