Import your data
my_data <- read_excel("../00_data/myData_all.xlsx")
my_data
## # A tibble: 220 × 7
## observed_month prod_type prod_process n_hens n_eggs source Eggs_Per_Hen
## <dttm> <chr> <chr> <dbl> <dbl> <chr> <dbl>
## 1 2016-07-31 00:00:00 hatching … all 5.80e7 1.15e9 ChicE… 19.8
## 2 2016-08-31 00:00:00 hatching … all 5.76e7 1.14e9 ChicE… 19.8
## 3 2016-09-30 00:00:00 hatching … all 5.72e7 1.09e9 ChicE… 19.1
## 4 2016-10-31 00:00:00 hatching … all 5.69e7 1.13e9 ChicE… 19.8
## 5 2016-11-30 00:00:00 hatching … all 5.71e7 1.10e9 ChicE… 19.2
## 6 2016-12-31 00:00:00 hatching … all 5.77e7 1.13e9 ChicE… 19.6
## 7 2017-01-31 00:00:00 hatching … all 5.80e7 1.12e9 ChicE… 19.4
## 8 2017-02-28 00:00:00 hatching … all 5.83e7 1.01e9 ChicE… 17.4
## 9 2017-03-31 00:00:00 hatching … all 5.87e7 1.13e9 ChicE… 19.2
## 10 2017-04-30 00:00:00 hatching … all 5.91e7 1.10e9 ChicE… 18.6
## # ℹ 210 more rows
Make data small
my_data_small <- my_data %>% select(observed_month, n_hens, n_eggs) %>% sample_n(10)
my_data_small
## # A tibble: 10 × 3
## observed_month n_hens n_eggs
## <dttm> <dbl> <dbl>
## 1 2018-05-31 00:00:00 15559000 361746617.
## 2 2020-01-31 00:00:00 15651500 368748720
## 3 2017-09-30 00:00:00 60202000 1120900000
## 4 2019-12-31 00:00:00 16226500 383553257.
## 5 2019-04-30 00:00:00 62900000 1165600000
## 6 2017-07-31 00:00:00 27500000 643637057.
## 7 2018-06-30 00:00:00 62428000 1161400000
## 8 2018-10-31 00:00:00 60889000 1184200000
## 9 2016-09-30 00:00:00 57161000 1093300000
## 10 2018-02-28 00:00:00 14996000 313866720
Separating and Uniting
Unite two columns
my_data_small_unite <- my_data_small %>%
unite(col = "rate", c(n_eggs, n_hens), sep = "/", )
my_data_small_unite
## # A tibble: 10 × 2
## observed_month rate
## <dttm> <chr>
## 1 2018-05-31 00:00:00 361746617.142857/15559000
## 2 2020-01-31 00:00:00 368748720/15651500
## 3 2017-09-30 00:00:00 1120900000/60202000
## 4 2019-12-31 00:00:00 383553257.142857/16226500
## 5 2019-04-30 00:00:00 1165600000/62900000
## 6 2017-07-31 00:00:00 643637057.142857/27500000
## 7 2018-06-30 00:00:00 1161400000/62428000
## 8 2018-10-31 00:00:00 1184200000/60889000
## 9 2016-09-30 00:00:00 1093300000/57161000
## 10 2018-02-28 00:00:00 313866720/14996000
Separate a column
my_data_small_sep <- my_data_small_unite %>%
separate(col = rate, into = c("n_eggs", "n_hens"))
## Warning: Expected 2 pieces. Additional pieces discarded in 3 rows [1, 4, 6].
my_data_small_sep
## # A tibble: 10 × 3
## observed_month n_eggs n_hens
## <dttm> <chr> <chr>
## 1 2018-05-31 00:00:00 361746617 142857
## 2 2020-01-31 00:00:00 368748720 15651500
## 3 2017-09-30 00:00:00 1120900000 60202000
## 4 2019-12-31 00:00:00 383553257 142857
## 5 2019-04-30 00:00:00 1165600000 62900000
## 6 2017-07-31 00:00:00 643637057 142857
## 7 2018-06-30 00:00:00 1161400000 62428000
## 8 2018-10-31 00:00:00 1184200000 60889000
## 9 2016-09-30 00:00:00 1093300000 57161000
## 10 2018-02-28 00:00:00 313866720 14996000
Missing Values