Data types of classes

Lecture 8

Dr. Mine Çetinkaya-Rundel

Duke University
STA 113 - Fall 2023

Warm up

While you wait

Check your email for an email from TEAMMATES. Provide peer feedback to your teammates (and to yourself). Be constructive and encouraging!

Course content

  • Today: Last day of “welcome to R” content

  • Remainder of class: Greater emphasis on “data visualization with R”

Project 1

  • Proposals have been reviewed and each team has a number of issues on their repos with my feedback

  • Between today and next Tuesday: Review proposal feedback, improve your proposals by closing issues with specific commits (more on this in a few), move on from working on your proposal to your project and make progress, particularly working on your visualizations

  • Next Tuesday: Start with peer review, then learn about polishing your plots

  • Next Tuesday - Thursday: Improve your projects by closing peer review issue with specific commits, finalize your presentation and your writeup

  • Next Thursday: Project presentations

Project webpages

  • Each of you now have a webpage for your projects!

  • This was achieved by adding a _quarto.yml file to each of your repos.

  • The first thing you should do is go to your Posit Cloud project and, in the Git tab, pull my changes from your repo.
  • Then, relaunch your project – three dots on top right > Relaunch.
  • Going forward, when you want to see the output of what you’re working on, click on Render Project in the Build tab.

Addressing proposal feedback

  • Each piece of feedback is noted as an issue
  • Review each issue and address them – that means make a correction to your project that specifically addresses that issue, commit with a message like

    Moved dataset into the data folder, closes #1.

    where #1 refers to the issue number, and push. This will close the issue and associate the commit that addressed it with the issue.

Project questions?

before we get back to our regularly scheduled programming…

Types and classes

Types and classes

  • Type is how an object is stored in memory, e.g.,

    • double: a real number stored in double-precision floating point format.
    • integer: an integer (positive or negative)
  • Class is metadata about the object that can determine how common functions operate on that object, e.g.,

  • factor

Types of vectors

You’ll commonly encounter:

  • logical
  • integer
  • double
  • character

You’ll less commonly encounter:

  • list
  • NULL
  • complex
  • raw

Types of functions

Yes, functions have types too, but you don’t need to worry about the differences in the context of doing data science.

typeof(mean) # regular function
[1] "closure"
typeof(`$`) # internal function
[1] "special"
typeof(sum) # primitive function
[1] "builtin"

Factors

A factor is a vector that can contain only predefined values. It is used to store categorical data.

x <- factor(c("a", "b", "b", "a"))
x
[1] a b b a
Levels: a b
typeof(x)
[1] "integer"
attributes(x)
$levels
[1] "a" "b"

$class
[1] "factor"

Other classes

Just a couple of examples…

Date:

today <- Sys.Date()
today
[1] "2023-10-05"
typeof(today)
[1] "double"
attributes(today)
$class
[1] "Date"

Date-time:

now <- as.POSIXct("2022-09-22 10:15", tz = "EST")
now
[1] "2022-09-22 10:15:00 EST"
typeof(now)
[1] "double"
attributes(now)
$class
[1] "POSIXct" "POSIXt" 

$tzone
[1] "EST"

ae-08

  • Go to the course GitHub org and find your ae-08-hotels (repo name will be suffixed with your GitHub name).
  • Clone the repo in Posit Cloud, open the Quarto document in the repo, set up a new PAT, and follow along and complete the exercises.
  • Render, commit, and push your edits as you work through it