DACSS 601: Data Science Fundamentals - FALL 2022
  • Fall 2022 Posts
  • Contributors
  • DACSS

Challenge 2 Instructions

  • Course information
    • Overview
    • Instructional Team
    • Course Schedule
  • Weekly materials
    • Fall 2022 posts
    • final posts

On this page

  • Challenge Overview
  • Data Read In
  • Provide Grouped Summary Statistics

Challenge 2 Instructions

  • Show All Code
  • Hide All Code

  • View Source
challenge_2
railroads
faostat
hotel_bookings
Author

Kim Darkenwald

Published

October 12, 2022

Code
library(tidyverse)
library(readr)

knitr::opts_chunk$set(echo = TRUE, warning=FALSE, message=FALSE)

Challenge Overview

Data Read In

Code
birds <- read_csv("_data/birds.csv")
birds
# A tibble: 30,977 × 14
   Domain Cod…¹ Domain Area …² Area  Eleme…³ Element Item …⁴ Item  Year …⁵  Year
   <chr>        <chr>    <dbl> <chr>   <dbl> <chr>     <dbl> <chr>   <dbl> <dbl>
 1 QA           Live …       2 Afgh…    5112 Stocks     1057 Chic…    1961  1961
 2 QA           Live …       2 Afgh…    5112 Stocks     1057 Chic…    1962  1962
 3 QA           Live …       2 Afgh…    5112 Stocks     1057 Chic…    1963  1963
 4 QA           Live …       2 Afgh…    5112 Stocks     1057 Chic…    1964  1964
 5 QA           Live …       2 Afgh…    5112 Stocks     1057 Chic…    1965  1965
 6 QA           Live …       2 Afgh…    5112 Stocks     1057 Chic…    1966  1966
 7 QA           Live …       2 Afgh…    5112 Stocks     1057 Chic…    1967  1967
 8 QA           Live …       2 Afgh…    5112 Stocks     1057 Chic…    1968  1968
 9 QA           Live …       2 Afgh…    5112 Stocks     1057 Chic…    1969  1969
10 QA           Live …       2 Afgh…    5112 Stocks     1057 Chic…    1970  1970
# … with 30,967 more rows, 4 more variables: Unit <chr>, Value <dbl>,
#   Flag <chr>, `Flag Description` <chr>, and abbreviated variable names
#   ¹​`Domain Code`, ²​`Area Code`, ³​`Element Code`, ⁴​`Item Code`, ⁵​`Year Code`
Code
view(birds)
Code
dim(birds)
[1] 30977    14
Code
colnames(birds)
 [1] "Domain Code"      "Domain"           "Area Code"        "Area"            
 [5] "Element Code"     "Element"          "Item Code"        "Item"            
 [9] "Year Code"        "Year"             "Unit"             "Value"           
[13] "Flag"             "Flag Description"
Code
birds %>%
  select("Area", "Item", "Year", "Unit", "Value", "Flag Description") %>%
  filter(Area == "World", Item == "Chickens") %>%
  arrange(desc("Year"))
# A tibble: 58 × 6
   Area  Item      Year Unit        Value `Flag Description`                    
   <chr> <chr>    <dbl> <chr>       <dbl> <chr>                                 
 1 World Chickens  1961 1000 Head 3906690 Aggregate, may include official, semi…
 2 World Chickens  1962 1000 Head 4048728 Aggregate, may include official, semi…
 3 World Chickens  1963 1000 Head 4163131 Aggregate, may include official, semi…
 4 World Chickens  1964 1000 Head 4231221 Aggregate, may include official, semi…
 5 World Chickens  1965 1000 Head 4349674 Aggregate, may include official, semi…
 6 World Chickens  1966 1000 Head 4445629 Aggregate, may include official, semi…
 7 World Chickens  1967 1000 Head 4666511 Aggregate, may include official, semi…
 8 World Chickens  1968 1000 Head 4823170 Aggregate, may include official, semi…
 9 World Chickens  1969 1000 Head 4988438 Aggregate, may include official, semi…
10 World Chickens  1970 1000 Head 5209733 Aggregate, may include official, semi…
# … with 48 more rows
Code
birds %>%
  select("Area", "Item", "Year", "Unit", "Value", "Flag Description") %>%
  filter(Area == "World", Item == "Turkeys") %>%
  arrange(desc("Year"))
# A tibble: 58 × 6
   Area  Item     Year Unit       Value `Flag Description`                      
   <chr> <chr>   <dbl> <chr>      <dbl> <chr>                                   
 1 World Turkeys  1961 1000 Head 204241 Aggregate, may include official, semi-o…
 2 World Turkeys  1962 1000 Head 174077 Aggregate, may include official, semi-o…
 3 World Turkeys  1963 1000 Head 161262 Aggregate, may include official, semi-o…
 4 World Turkeys  1964 1000 Head 153758 Aggregate, may include official, semi-o…
 5 World Turkeys  1965 1000 Head 154790 Aggregate, may include official, semi-o…
 6 World Turkeys  1966 1000 Head 166655 Aggregate, may include official, semi-o…
 7 World Turkeys  1967 1000 Head 174158 Aggregate, may include official, semi-o…
 8 World Turkeys  1968 1000 Head 155205 Aggregate, may include official, semi-o…
 9 World Turkeys  1969 1000 Head 157950 Aggregate, may include official, semi-o…
10 World Turkeys  1970 1000 Head 178971 Aggregate, may include official, semi-o…
# … with 48 more rows
Code
birds %>%
   select("Area", "Item", "Year", "Unit", "Value", "Flag Description") %>%
  filter(Area == "World") %>%
  summarize(Item, Year, Value) 
# A tibble: 290 × 3
   Item      Year   Value
   <chr>    <dbl>   <dbl>
 1 Chickens  1961 3906690
 2 Chickens  1962 4048728
 3 Chickens  1963 4163131
 4 Chickens  1964 4231221
 5 Chickens  1965 4349674
 6 Chickens  1966 4445629
 7 Chickens  1967 4666511
 8 Chickens  1968 4823170
 9 Chickens  1969 4988438
10 Chickens  1970 5209733
# … with 280 more rows

##Summary

This dataset contains information regarded birds around the world and by region. Specifically, chickens, turkeys, and pigeons. Between 1961 and 2018, the total amount of chickens worldwide increaed from 3,906,690 units to 23,707,134 units. A unit consists of 1000. From 1964 to 2018, the number of turkeys increased from 204241 units in 1961 to 466787 units. However, there was not steady increase every year, with some years descreasing in total.

*Please note I tried getting the data for 1961 & 2018 only, but had trouble doing so. I also struggled to get a list of “Items” or birds. I would like to know how to do this.

Code

birds %>%
   select("Area", "Item", "Year", "Unit", "Value", "Flag Description") %>%
  filter(Area == "World") %>%
  summarize(Item, Year, Value) %>%
  summarize(mean, `1960:1969`, `1970:1979`, `1980:1989`, `1990:1999`, `2000:2009`, `2010;2018)
    
  
   
  
Error: <text>:6:84: unexpected INCOMPLETE_STRING
10:   
11: 
                                                                                       ^

Provide Grouped Summary Statistics

I was trying to get the summary of total amounts of chickens for each decade, but struggled to do so.

Source Code
---
title: "Challenge 2 Instructions"
author: "Kim Darkenwald"
desription: "Data wrangling: using group() and summarise()"
date: "10/12/2022"
format:
  html:
    toc: true
    code-fold: true
    code-copy: true
    code-tools: true
categories:
  - challenge_2
  - railroads
  - faostat
  - hotel_bookings
---

```{r}
#| label: setup
#| warning: false
#| message: false

library(tidyverse)
library(readr)

knitr::opts_chunk$set(echo = TRUE, warning=FALSE, message=FALSE)
```

## Challenge Overview

## Data Read In

```{r}
birds <- read_csv("_data/birds.csv")
birds
view(birds)


```



```{r}
#| label: summary

dim(birds)
colnames(birds)
birds %>%
  select("Area", "Item", "Year", "Unit", "Value", "Flag Description") %>%
  filter(Area == "World", Item == "Chickens") %>%
  arrange(desc("Year"))

birds %>%
  select("Area", "Item", "Year", "Unit", "Value", "Flag Description") %>%
  filter(Area == "World", Item == "Turkeys") %>%
  arrange(desc("Year"))



```

```{r}
birds %>%
   select("Area", "Item", "Year", "Unit", "Value", "Flag Description") %>%
  filter(Area == "World") %>%
  summarize(Item, Year, Value) 
  
 
```

##Summary

This dataset contains information regarded birds around the world and by region. Specifically, chickens, turkeys, and pigeons. Between 1961 and 2018, the total amount of chickens worldwide increaed from 3,906,690 units to 23,707,134 units. A unit consists of 1000.  From 1964 to 2018, the number of turkeys increased from 204241    units in 1961 to  466787 units. However, there was not steady increase every year, with some years descreasing in total.

*Please note I tried getting the data for 1961 & 2018 only, but had trouble doing so. I also struggled to get a list of "Items" or birds. I would like to know how to do this.



```{r}
birds %>%
   select("Area", "Item", "Year", "Unit", "Value", "Flag Description") %>%
  filter(Area == "World") %>%
  summarize(Item, Year, Value) %>%
  summarize(mean, `1960:1969`, `1970:1979`, `1980:1989`, `1990:1999`, `2000:2009`, `2010;2018)
    
  
   
  

```

## Provide Grouped Summary Statistics

I was trying to get the summary of total amounts of chickens for each decade, but struggled to do so.