Challenge 3 Instructions

challenge_3
animal_weights
eggs
australian_marriage
usa_households
sce_labor
Author

Khadijat Adeleye

Published

March 19, 2023

Code
library(tidyverse)

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

Challenge Overview

Code
data<-read.csv("_data\\animal_weight.csv")
view(data)
nrow(data)
[1] 9
Code
ncol(data)
[1] 17
Code
list(colnames(data))
[[1]]
 [1] "IPCC.Area"          "Cattle...dairy"     "Cattle...non.dairy"
 [4] "Buffaloes"          "Swine...market"     "Swine...breeding"  
 [7] "Chicken...Broilers" "Chicken...Layers"   "Ducks"             
[10] "Turkeys"            "Sheep"              "Goats"             
[13] "Horses"             "Asses"              "Mules"             
[16] "Camels"             "Llamas"            

describe the data

The data set contains 9 observations with 17 variables from different continents.

Code
nrow(data) * (ncol(data)-3)
[1] 126

Any additional comments? Expected column is 126 ## Pivot the Data

Code
data<-pivot_longer(data, col = c(Turkeys,Ducks),
                 names_to="Animal_name",
                 values_to = "animal_value")
Code
data
# A tibble: 18 × 17
   IPCC.Area Cattl…¹ Cattl…² Buffa…³ Swine…⁴ Swine…⁵ Chick…⁶ Chick…⁷ Sheep Goats
   <chr>       <int>   <int>   <int>   <int>   <int>   <dbl>   <dbl> <dbl> <dbl>
 1 Indian S…     275     110     295      28      28     0.9     1.8  28    30  
 2 Indian S…     275     110     295      28      28     0.9     1.8  28    30  
 3 Eastern …     550     391     380      50     180     0.9     1.8  48.5  38.5
 4 Eastern …     550     391     380      50     180     0.9     1.8  48.5  38.5
 5 Africa        275     173     380      28      28     0.9     1.8  28    30  
 6 Africa        275     173     380      28      28     0.9     1.8  28    30  
 7 Oceania       500     330     380      45     180     0.9     1.8  48.5  38.5
 8 Oceania       500     330     380      45     180     0.9     1.8  48.5  38.5
 9 Western …     600     420     380      50     198     0.9     1.8  48.5  38.5
10 Western …     600     420     380      50     198     0.9     1.8  48.5  38.5
11 Latin Am…     400     305     380      28      28     0.9     1.8  28    30  
12 Latin Am…     400     305     380      28      28     0.9     1.8  28    30  
13 Asia          350     391     380      50     180     0.9     1.8  48.5  38.5
14 Asia          350     391     380      50     180     0.9     1.8  48.5  38.5
15 Middle e…     275     173     380      28      28     0.9     1.8  28    30  
16 Middle e…     275     173     380      28      28     0.9     1.8  28    30  
17 Northern…     604     389     380      46     198     0.9     1.8  48.5  38.5
18 Northern…     604     389     380      46     198     0.9     1.8  48.5  38.5
# … with 7 more variables: Horses <int>, Asses <int>, Mules <int>,
#   Camels <int>, Llamas <int>, Animal_name <chr>, animal_value <dbl>, and
#   abbreviated variable names ¹​Cattle...dairy, ²​Cattle...non.dairy,
#   ³​Buffaloes, ⁴​Swine...market, ⁵​Swine...breeding, ⁶​Chicken...Broilers,
#   ⁷​Chicken...Layers

The number of row has increased to 18

Code
nrow(data)
[1] 18
Code
ncol(data)
[1] 17