Data Types - Cghlewis/data-wrangling-functions GitHub Wiki
Some of the most common variable classes you will encounter include:
- Character
- Numeric (Double)
- Integer
- Factor
- Date
- POSIXt
- Logical
And common data types include:
- Character
- Numeric (Double)
- Integer
- Logical
Review variable structure
Convert variable class
- Convert variable class to numeric
- [Remove non-numeric values and convert to numeric](See Strings)
- Convert variable class to character
- Convert variable class to factor
- Convert variable class to date
Convert variable class using a dictionary
Main functions used in examples
| Package | Functions |
|---|---|
| base | class(); typeof(); as.factor(); as.numeric(); as.character() |
| utils | str() |
| lubridate | as_date(); as_datetime(); mdy(); parse_date_time() |
| forcats | as_factor(); fct_relevel() |
| janitor | excel_numeric_to_date() |
| dplyr | glimpse() |
Other functions used in examples
| Package | Functions |
|---|---|
| base | attributes(); levels(); paste0() |
| dplyr | mutate(); across(); all_of(); pull() |
| purrr | map() |
| tidyselect | everything(); where() |
| lubridate | month(); day() |
Resources
- https://tibble.tidyverse.org/articles/types.html
- https://swcarpentry.github.io/r-novice-inflammation/13-supp-data-structures/
- https://resbaz.github.io/2014-r-materials/lessons/01-intro_r/data-structures.html
- https://mgimond.github.io/ES218/Week02a.html
- https://stackoverflow.com/questions/8855589/a-comprehensive-survey-of-the-types-of-things-in-r-mode-and-class-and-type
- https://evoldyn.gitlab.io/evomics-2018/ref-sheets/R_lubridate.pdf
- https://www.youtube.com/watch?v=_rPde-SPDVE
- https://www.youtube.com/watch?v=OEweA4yVAuI
- https://www.r-bloggers.com/2013/08/date-formats-in-r/
- https://rdrr.io/cran/janitor/man/excel_numeric_to_date.html
- https://epirhandbook.com/en/working-with-dates.html