# A tibble: 4 × 2
tue_classes year
<chr> <chr>
1 <NA> <NA>
2 2 Sophomore
3 three First-year
4 1 Senior
Lecture 9
Duke University
STA 199 - Fall 2025
September 23, 2025
Fill in the blanks:
I’m a _____
(first-year, sophomore, junior, senior)
and on Tuesdays I have _____
class(es).
Scan the QR code or go to app.wooclap.com/sta199. Log in with your Duke NetID.
Survey: Confidence in STEM courses at Duke
Exam 1:
What type of variable is tue_classes
?
Vectors can be constructed using the c()
function.
with intention…
with intention…
without intention…
R will happily convert between various types without complaint when different types of data are concatenated in a vector, and that’s not always a great thing!
without intention…
What is the output of typeof(c(1.2, 3L))
?
"character"
"double"
"integer"
"logical"
Scan the QR code or go to app.wooclap.com/sta199. Log in with your Duke NetID.
Explicit coercion:
When you call a function like as.logical()
, as.numeric()
, as.integer()
, as.double()
, or as.character()
.
Implicit coercion:
Happens when you use a vector in a specific context that expects a certain type of vector.
R uses factors to handle categorical variables, variables that have a fixed and known set of possible values
We can think of factors like character (level labels) and an integer (level numbers) glued together
We can think of dates like an integer (the number of days since the origin, 1 Jan 1970) and an integer (the origin) glued together
We can think of data frames like like vectors of equal length glued together
Lists are a generic vector container; vectors of any type can go in them
pull()
function, we extract a vector from the data framesurvey |>
mutate(
year = fct_relevel(year, "First-year", "Sophomore", "Junior", "Senior")
) |>
ggplot(mapping = aes(x = year)) +
geom_bar()
Warning: There was 1 warning in `mutate()`.
ℹ In argument: `year = fct_relevel(year, "First-year", "Sophomore",
"Junior", "Senior")`.
Caused by warning:
! 1 unknown level in `f`: Junior
Reordering levels by:
fct_relevel()
: hand
fct_infreq()
: frequency
fct_reorder()
: sorting along another variable
fct_rev()
: reversing
…
Changing level values by:
fct_lump()
: lumping uncommon levels together into “other”
fct_other()
: manually replacing some levels with “other”
…
Go to your ae project in RStudio.
If you haven’t yet done so, make sure all of your changes up to this point are committed and pushed, i.e., there’s nothing left in your Git pane.
If you haven’t yet done so, click Pull to get today’s application exercise file: ae-07-durham-climate-factors.qmd.
Work through the application exercise in class, and render, commit, and push your edits by the end of class.