Code
library(tidyverse)
::opts_chunk$set(echo = TRUE, warning=FALSE, message=FALSE) knitr
Sanjana Jhaveri
August 18, 2022
Today’s challenge is to:
Read in one (or more) of the following datasets, using the correct R package and command.
The dimensions of the data set is huge, so trimming all the unnecessary information will be needed. I can already see that the column ppeduc5 and ppeducat are identical so one can be removed. I’m not sure what weight_pid indicates so I will be removing that as well. Column 3 (complete_status) seems irrelevant to the data that I want to decipher so I will be deleting that as well. ## Tidy Data (as needed)
Is your data already tidy, or is there work to be done? Be sure to anticipate your end result to provide a sanity check, and document your work here.
abc_poll_2021 <- read_csv("_data/abc_poll_2021.csv",
skip = 1,
col_names = c("id", "delete", "delete", "delete", "delete", "education", "gender", "ethnicity", "household_size", "income",
"marital status", "delete", "delete", "rental", "state", "employment", "delete", "delete", "delete", "delete", "delete", "delete", "delete", "delete", "delete", "delete", "feeling", "party", "age_range", "delete", "delete")) %>%
select(!starts_with("delete")) %>%
na_if("Skipped") %>%
mutate(rental = fct_recode(rental,
"Owned" = "Owned or being bought by you or someone in your household",
"Rental" = "Rented for cash",
"Other" = "Occupied without payment of cash rent"))
Any additional comments?
Are there any variables that require mutation to be usable in your analysis stream? For example, are all time variables correctly coded as dates? Are all string variables reduced and cleaned to sensible categories? Do you need to turn any variables into factors and reorder for ease of graphics and visualization?
Document your work here.
I only mutated the rental column to cut down the wordiness of the row. and make it more sensible. Now it is just Owned, Rental and Other.
Variable | Stats / Values | Freqs (% of Valid) | Graph | Missing | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id [numeric] |
|
527 distinct values | 0 (0.0%) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
education [character] |
|
|
0 (0.0%) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
gender [character] |
|
|
0 (0.0%) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ethnicity [character] |
|
|
0 (0.0%) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
household_size [character] |
|
|
0 (0.0%) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
income [character] |
|
|
0 (0.0%) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
marital status [character] |
|
|
0 (0.0%) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
rental [factor] |
|
|
0 (0.0%) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
state [character] |
|
|
0 (0.0%) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
employment [character] |
|
|
0 (0.0%) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
feeling [character] |
|
|
3 (0.6%) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
party [character] |
|
|
3 (0.6%) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
age_range [character] |
|
|
0 (0.0%) |
Generated by summarytools 1.0.1 (R version 4.2.1)
2022-12-20
Any additional comments?
---
title: "Challenge 4"
author: "Sanjana Jhaveri"
desription: "More data wrangling: pivoting"
date: "08/18/2022"
format:
html:
toc: true
code-fold: true
code-copy: true
code-tools: true
categories:
- challenge_4
- abc_poll
- eggs
- fed_rates
- hotel_bookings
- debt
---
```{r}
#| label: setup
#| warning: false
#| message: false
library(tidyverse)
knitr::opts_chunk$set(echo = TRUE, warning=FALSE, message=FALSE)
```
## Challenge Overview
Today's challenge is to:
1) read in a data set, and describe the data set using both words and any supporting information (e.g., tables, etc)
2) tidy data (as needed, including sanity checks)
3) identify variables that need to be mutated
4) mutate variables and sanity check all mutations
## Read in data
Read in one (or more) of the following datasets, using the correct R package and command.
- abc_poll.csv ⭐
- poultry_tidy.xlsx or organiceggpoultry.xls⭐⭐
- FedFundsRate.csv⭐⭐⭐
- hotel_bookings.csv⭐⭐⭐⭐
- debt_in_trillions.xlsx ⭐⭐⭐⭐⭐
```{r}
library(readr)
library(knitr)
library(summarytools)
abc_poll_2021 <- read_csv("_data/abc_poll_2021.csv")
View(abc_poll_2021)
```
### Briefly describe the data
The dimensions of the data set is huge, so trimming all the unnecessary information will be needed. I can already see that the column ppeduc5 and ppeducat are identical so one can be removed. I'm not sure what weight_pid indicates so I will be removing that as well. Column 3 (complete_status) seems irrelevant to the data that I want to decipher so I will be deleting that as well.
## Tidy Data (as needed)
Is your data already tidy, or is there work to be done? Be sure to anticipate your end result to provide a sanity check, and document your work here.
```{r}
abc_poll_2021 <- read_csv("_data/abc_poll_2021.csv",
skip = 1,
col_names = c("id", "delete", "delete", "delete", "delete", "education", "gender", "ethnicity", "household_size", "income",
"marital status", "delete", "delete", "rental", "state", "employment", "delete", "delete", "delete", "delete", "delete", "delete", "delete", "delete", "delete", "delete", "feeling", "party", "age_range", "delete", "delete")) %>%
select(!starts_with("delete")) %>%
na_if("Skipped") %>%
mutate(rental = fct_recode(rental,
"Owned" = "Owned or being bought by you or someone in your household",
"Rental" = "Rented for cash",
"Other" = "Occupied without payment of cash rent"))
```
Any additional comments?
## Identify variables that need to be mutated
Are there any variables that require mutation to be usable in your analysis stream? For example, are all time variables correctly coded as dates? Are all string variables reduced and cleaned to sensible categories? Do you need to turn any variables into factors and reorder for ease of graphics and visualization?
Document your work here.
I only mutated the rental column to cut down the wordiness of the row. and make it more sensible. Now it is just Owned, Rental and Other.
```{r}
print(summarytools::dfSummary(abc_poll_2021,
varnumbers = FALSE,
plain.ascii = FALSE,
style = "grid",
graph.magnif = 0.70,
valid.col = FALSE),
method = 'render',
table.classes = 'table-condensed')
```
Any additional comments?