Code
library(tidyverse)
::opts_chunk$set(echo = TRUE, warning=FALSE, message=FALSE) knitr
Khadijat Adeleye
March 19, 2023
[[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"
The data set contains 9 observations with 17 variables from different continents.
Any additional comments? Expected column is 126 ## Pivot the 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
---
title: "Challenge 3 Instructions"
author: "Khadijat Adeleye"
desription: "Tidy Data: Pivoting"
date: "03/19/2023"
format:
html:
toc: true
code-fold: true
code-copy: true
code-tools: true
categories:
- challenge_3
- animal_weights
- eggs
- australian_marriage
- usa_households
- sce_labor
---
```{r}
#| label: setup
#| warning: false
#| message: false
library(tidyverse)
knitr::opts_chunk$set(echo = TRUE, warning=FALSE, message=FALSE)
```
## Challenge Overview
```{r}
data<-read.csv("_data\\animal_weight.csv")
view(data)
nrow(data)
ncol(data)
```
```{r}
list(colnames(data))
```
### describe the data
The data set contains 9 observations with 17 variables from different continents.
```{r}
nrow(data) * (ncol(data)-3)
```
Any additional comments?
Expected column is 126
## Pivot the Data
```{r}
data<-pivot_longer(data, col = c(Turkeys,Ducks),
names_to="Animal_name",
values_to = "animal_value")
```
```{r}
data
```
The number of row has increased to 18
```{r}
nrow(data)
```
```{r}
ncol(data)
```