-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfoodloss_se_descriptive_table.Rmd
63 lines (44 loc) · 1.43 KB
/
foodloss_se_descriptive_table.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
---
title: "SE descriptive"
author: "Johannes Piipponen"
date: "Spring 2023`"
output: html_document
---
Code written by Johannes Piipponen
# Create table of socio-economic variables
```{r}
library(plotrix)
library(tidyverse)
# Get Daniel's data
daniel_original <- read.csv("data_johannes.csv")
# Explore descriptive statistics using the original data
df_se_descriptive <-
daniel_original %>%
group_by(incLevel, basketItem2, food_supply_stage) %>%
summarise(foodloss_mean = mean(loss_percentage1),
StandardError = std.error(loss_percentage1),
N = n()) %>%
mutate_if(is.numeric, round, digits = 3)
# alternatively, use data with polygons
# df_se_descriptive <-
# country_data %>%
# st_drop_geometry() %>%
# group_by(incLevel, basketItem2, food_supply_stage) %>%
# summarise(foodloss_mean = mean(loss_percentage1),
# StandardError = std.error(loss_percentage1),
# N = n()) %>%
# mutate_if(is.numeric, round, digits = 3)
# Modify the table to have L and M countries side by side
df_se_descriptive_L <- df_se_descriptive %>%
filter(incLevel == "L") %>%
dplyr::select(-incLevel)
df_se_descriptive_M <- df_se_descriptive %>%
filter(incLevel == "M") %>%
dplyr::select(-incLevel)
# Join the modified tables
df_se_table <-
left_join(df_se_descriptive_L, df_se_descriptive_M,
by = c("basketItem2", "food_supply_stage"))
df_se_table
#View(df_se_table)
```