Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions modules/Data_Classes/Data_Classes.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -139,33 +139,33 @@ Examples:

## Classes Overview

| Example | Class | Type | Notes |
|:---:|:---:|:---:|---|
| 1.1 | Numeric | double | default for numbers |
| 1 | integer | integer | Need to coerce to integer with as.integer() or use sample() or seq() with whole numbers |
| "FALSE", "Ball" | Character | Character | Need quotes |
| FALSE, TRUE | logical | logical | No quotes |
| "Small", "Large" | Factor | Factor | Need to coerce to factor with factor() |
| Example | Class | Type | Notes |
|:----------------:|:---------:|:---------:|----------------------------------------------------------------------------------------------------|
| 1.1 | numeric | double | Default for numbers |
| 1 | integer | integer | Need to coerce to integer with `as.integer()` or use `sample()` or `seq()` to create whole numbers |
| "FALSE", "Ball" | character | character | Need quotes |
| FALSE, TRUE | logical | logical | No quotes, 0 and 1, respectively |
| "Small", "Large" | factor | factor | Need to coerce to factor with `factor()` |

# Special data classes

## Dates

There are two most popular R classes used when working with dates and times:

- `Date` class representing a calendar date
- `POSIXct` class representing a calendar date with hours, minutes, seconds
- `Date` class - a calendar date
- `POSIXct` class - a calendar date with hours, minutes, seconds

We convert data from character to `Date`/`POSIXct` to use functions to manipulate date/date and time
Converting data from character to `Date`/`POSIXct` allows special functions date/date and time

`lubridate` is a powerful, widely used R package from "tidyverse" family to work with `Date` / `POSIXct` class objects
`lubridate` (part of `tidyverse`) helps work with `Date` / `POSIXct` class objects

## Creating `Date` class object

```{r, message = FALSE}
class("2021-06-15")

library(lubridate)
library(tidyverse) # Contains lubridate

x <- ymd("2021-06-15") # lubridate package Year Month Day
class(x)
Expand Down
Loading