From 7a2c2820f8c4ab44a7cc346c85f89f7aab703e19 Mon Sep 17 00:00:00 2001 From: annaramji Date: Wed, 3 Jul 2024 21:07:47 +0000 Subject: [PATCH] calculated aqf revenue, saved int data, updated function for tidying fao commodity data --- globalprep/le/v2024/af_dataprep.Rmd | 27 +- globalprep/le/v2024/int/aqf_revenue.csv | 319 ++++++++++++++++++++++++ workflow/R/fao_query_data_tidy.R | 12 +- 3 files changed, 344 insertions(+), 14 deletions(-) create mode 100644 globalprep/le/v2024/int/aqf_revenue.csv diff --git a/globalprep/le/v2024/af_dataprep.Rmd b/globalprep/le/v2024/af_dataprep.Rmd index fef93cb7..90b65056 100644 --- a/globalprep/le/v2024/af_dataprep.Rmd +++ b/globalprep/le/v2024/af_dataprep.Rmd @@ -121,7 +121,7 @@ commodities_value_raw %>% filter(`2021 Flag` == "N") ``` -## Data cleaning +## Data cleaning & Wrangling ```{r} # adapted from the v2023 livelihood_economies_dataprep.Rmd @@ -132,7 +132,8 @@ ornamental_value <- commodities_value_raw %>% janitor::clean_names() %>% # filter to ornamental commodities filter(str_detect(commodity_name_en, "Ornamental")) %>% - rename(country = "reporting_country_name_en", # COME BACK -- not sure about this + rename(country = "reporting_country_name_en", + partner_country = "partner_country_name_en", commodity = "commodity_name_en", trade = "trade_flow_name_en") %>% filter(trade == "Exports" & commodity != "Ornamental freshwater fish") %>% # remove all other fish (commodities) that are not ornamentals (bc aquarium = ornamental), don't include the freshwater ornamental fish (interested in saltwater/ocean only) @@ -142,18 +143,26 @@ ornamental_value <- commodities_value_raw %>% mutate(value = (value * 1000), # convert from thousands to single dollar unit = "USD (1)") %>% # add iso3 column - mutate(iso3 = country_regex_to_iso3c(country)) # COME BACK + mutate(iso3 = country_regex_to_iso3c(country)) # get iso3 code of reporting country +``` + + -# fao_query_data_tidy()# sum for each country -ornamental_revenue <- ornamental_value_raw %>% +```{r} +# sum for each country +ornamental_revenue <- ornamental_value %>% group_by(country, year) %>% - summarize(value = sum(value, na.rm = TRUE), unit = first(unit)) %>% - mutate(sector = "aqf", #c ode for aquarium fishing sector + summarize(value = sum(value, na.rm = TRUE), + unit = first(unit)) %>% + mutate(sector = "aqf", # code for aquarium fishing sector data_source = "FAO global trade") %>% - select(country, year, value, unit, sector, data_source) + select(country, year, value, unit, sector, data_source) %>% + # add iso3 column + mutate(iso3 = country_regex_to_iso3c(country)) %>% # get iso3 code of reporting country + relocate(iso3, .after = country) # write as intermediate file -write_csv(ornamental_revenue, here(data_path, "int", "aqf_revenue.csv")) +write_csv(ornamental_revenue, here(int_dir, "aqf_revenue.csv")) ``` diff --git a/globalprep/le/v2024/int/aqf_revenue.csv b/globalprep/le/v2024/int/aqf_revenue.csv new file mode 100644 index 00000000..76d22668 --- /dev/null +++ b/globalprep/le/v2024/int/aqf_revenue.csv @@ -0,0 +1,319 @@ +country,iso3,year,value,unit,sector,data_source +Afghanistan,AFG,2019,0,USD (1),aqf,FAO global trade +Afghanistan,AFG,2020,130.89999999999998,USD (1),aqf,FAO global trade +Afghanistan,AFG,2021,0,USD (1),aqf,FAO global trade +Armenia,ARM,2019,0,USD (1),aqf,FAO global trade +Armenia,ARM,2020,0,USD (1),aqf,FAO global trade +Armenia,ARM,2021,6689.4,USD (1),aqf,FAO global trade +Aruba,ABW,2019,5625.0999999999995,USD (1),aqf,FAO global trade +Aruba,ABW,2020,0,USD (1),aqf,FAO global trade +Aruba,ABW,2021,0,USD (1),aqf,FAO global trade +Australia,AUS,2019,1563488.5,USD (1),aqf,FAO global trade +Australia,AUS,2020,827864.4,USD (1),aqf,FAO global trade +Australia,AUS,2021,1084103.3,USD (1),aqf,FAO global trade +Bahrain,BHR,2019,26170.2,USD (1),aqf,FAO global trade +Bahrain,BHR,2020,0,USD (1),aqf,FAO global trade +Bahrain,BHR,2021,127659.59999999999,USD (1),aqf,FAO global trade +Bangladesh,BGD,2019,62525.2,USD (1),aqf,FAO global trade +Bangladesh,BGD,2020,0,USD (1),aqf,FAO global trade +Bangladesh,BGD,2021,0,USD (1),aqf,FAO global trade +Belgium,BEL,2019,60800.9,USD (1),aqf,FAO global trade +Belgium,BEL,2020,304787.7,USD (1),aqf,FAO global trade +Belgium,BEL,2021,103535.8,USD (1),aqf,FAO global trade +Botswana,BWA,2019,420.2,USD (1),aqf,FAO global trade +Botswana,BWA,2020,0,USD (1),aqf,FAO global trade +Botswana,BWA,2021,0,USD (1),aqf,FAO global trade +Brazil,BRA,2019,239224,USD (1),aqf,FAO global trade +Brazil,BRA,2020,116326,USD (1),aqf,FAO global trade +Brazil,BRA,2021,191697,USD (1),aqf,FAO global trade +Bulgaria,BGR,2019,432288.4,USD (1),aqf,FAO global trade +Bulgaria,BGR,2020,762125.7,USD (1),aqf,FAO global trade +Bulgaria,BGR,2021,661972.7,USD (1),aqf,FAO global trade +Burundi,BDI,2019,0,USD (1),aqf,FAO global trade +Burundi,BDI,2020,0,USD (1),aqf,FAO global trade +Burundi,BDI,2021,20.2,USD (1),aqf,FAO global trade +Canada,CAN,2019,0,USD (1),aqf,FAO global trade +Canada,CAN,2020,0,USD (1),aqf,FAO global trade +Canada,CAN,2021,9494.6,USD (1),aqf,FAO global trade +China,CHN,2019,11789,USD (1),aqf,FAO global trade +China,CHN,2020,0,USD (1),aqf,FAO global trade +China,CHN,2021,0,USD (1),aqf,FAO global trade +"China, Hong Kong SAR",HKG,2019,400248.39999999997,USD (1),aqf,FAO global trade +"China, Hong Kong SAR",HKG,2020,242662.59999999998,USD (1),aqf,FAO global trade +"China, Hong Kong SAR",HKG,2021,301209.7,USD (1),aqf,FAO global trade +"China, Macao SAR",MAC,2019,0,USD (1),aqf,FAO global trade +"China, Macao SAR",MAC,2020,0,USD (1),aqf,FAO global trade +"China, Macao SAR",MAC,2021,0,USD (1),aqf,FAO global trade +Colombia,COL,2019,1254942.5,USD (1),aqf,FAO global trade +Colombia,COL,2020,57437.9,USD (1),aqf,FAO global trade +Colombia,COL,2021,3281.4,USD (1),aqf,FAO global trade +Congo,COG,2019,0,USD (1),aqf,FAO global trade +Congo,COG,2020,0,USD (1),aqf,FAO global trade +Congo,COG,2021,902.1,USD (1),aqf,FAO global trade +Cook Islands,COK,2019,10361.7,USD (1),aqf,FAO global trade +Cook Islands,COK,2020,0,USD (1),aqf,FAO global trade +Cook Islands,COK,2021,0,USD (1),aqf,FAO global trade +Costa Rica,CRI,2019,241626.69999999998,USD (1),aqf,FAO global trade +Costa Rica,CRI,2020,124265.90000000001,USD (1),aqf,FAO global trade +Costa Rica,CRI,2021,260928.19999999998,USD (1),aqf,FAO global trade +Cuba,CUB,2019,5337.8,USD (1),aqf,FAO global trade +Cuba,CUB,2020,14438.599999999999,USD (1),aqf,FAO global trade +Cuba,CUB,2021,26608.5,USD (1),aqf,FAO global trade +Curaçao,CUW,2019,5832.4,USD (1),aqf,FAO global trade +Curaçao,CUW,2020,11574.5,USD (1),aqf,FAO global trade +Curaçao,CUW,2021,14244.5,USD (1),aqf,FAO global trade +Czechia,CZE,2019,7239.7,USD (1),aqf,FAO global trade +Czechia,CZE,2020,131.39999999999998,USD (1),aqf,FAO global trade +Czechia,CZE,2021,9729.2,USD (1),aqf,FAO global trade +Côte d'Ivoire,CIV,2019,0,USD (1),aqf,FAO global trade +Côte d'Ivoire,CIV,2020,859.9,USD (1),aqf,FAO global trade +Côte d'Ivoire,CIV,2021,0,USD (1),aqf,FAO global trade +Democratic Republic of the Congo,COD,2019,0,USD (1),aqf,FAO global trade +Democratic Republic of the Congo,COD,2020,0,USD (1),aqf,FAO global trade +Democratic Republic of the Congo,COD,2021,49.9,USD (1),aqf,FAO global trade +Denmark,DNK,2019,0,USD (1),aqf,FAO global trade +Denmark,DNK,2020,2664.7,USD (1),aqf,FAO global trade +Denmark,DNK,2021,633.9,USD (1),aqf,FAO global trade +Djibouti,DJI,2019,508907.8,USD (1),aqf,FAO global trade +Djibouti,DJI,2020,630743.7999999999,USD (1),aqf,FAO global trade +Djibouti,DJI,2021,707341.3,USD (1),aqf,FAO global trade +Dominica,DMA,2019,987.5,USD (1),aqf,FAO global trade +Dominica,DMA,2020,127,USD (1),aqf,FAO global trade +Dominica,DMA,2021,0,USD (1),aqf,FAO global trade +Dominican Republic,DOM,2019,498.1,USD (1),aqf,FAO global trade +Dominican Republic,DOM,2020,703.4,USD (1),aqf,FAO global trade +Dominican Republic,DOM,2021,327,USD (1),aqf,FAO global trade +Ecuador,ECU,2019,32765,USD (1),aqf,FAO global trade +Ecuador,ECU,2020,16139,USD (1),aqf,FAO global trade +Ecuador,ECU,2021,11968,USD (1),aqf,FAO global trade +Egypt,EGY,2019,94559.7,USD (1),aqf,FAO global trade +Egypt,EGY,2020,45830.8,USD (1),aqf,FAO global trade +Egypt,EGY,2021,87965,USD (1),aqf,FAO global trade +Fiji,FJI,2019,1181520.7,USD (1),aqf,FAO global trade +Fiji,FJI,2020,1562107,USD (1),aqf,FAO global trade +Fiji,FJI,2021,2075796.5999999999,USD (1),aqf,FAO global trade +France,FRA,2019,1498802.9000000001,USD (1),aqf,FAO global trade +France,FRA,2020,1333688.6,USD (1),aqf,FAO global trade +France,FRA,2021,1842048.4,USD (1),aqf,FAO global trade +French Polynesia,PYF,2019,534708.2,USD (1),aqf,FAO global trade +French Polynesia,PYF,2020,267391.8,USD (1),aqf,FAO global trade +French Polynesia,PYF,2021,490996.7,USD (1),aqf,FAO global trade +Germany,DEU,2019,394374.1,USD (1),aqf,FAO global trade +Germany,DEU,2020,175724.3,USD (1),aqf,FAO global trade +Germany,DEU,2021,156535.7,USD (1),aqf,FAO global trade +Ghana,GHA,2019,72540.8,USD (1),aqf,FAO global trade +Ghana,GHA,2020,1620.1000000000001,USD (1),aqf,FAO global trade +Ghana,GHA,2021,2610.9,USD (1),aqf,FAO global trade +Guatemala,GTM,2019,0,USD (1),aqf,FAO global trade +Guatemala,GTM,2020,15531,USD (1),aqf,FAO global trade +Guatemala,GTM,2021,11424,USD (1),aqf,FAO global trade +Guinea,GIN,2019,1290.8,USD (1),aqf,FAO global trade +Guinea,GIN,2020,525.5999999999999,USD (1),aqf,FAO global trade +Guinea,GIN,2021,5623.2,USD (1),aqf,FAO global trade +Guyana,GUY,2019,3416.1000000000004,USD (1),aqf,FAO global trade +Guyana,GUY,2020,0,USD (1),aqf,FAO global trade +Guyana,GUY,2021,0,USD (1),aqf,FAO global trade +Haiti,HTI,2019,586057.2,USD (1),aqf,FAO global trade +Haiti,HTI,2020,310634.80000000005,USD (1),aqf,FAO global trade +Haiti,HTI,2021,132181.9,USD (1),aqf,FAO global trade +Hungary,HUN,2019,728.8,USD (1),aqf,FAO global trade +Hungary,HUN,2020,0,USD (1),aqf,FAO global trade +Hungary,HUN,2021,0,USD (1),aqf,FAO global trade +India,IND,2019,766068.7000000001,USD (1),aqf,FAO global trade +India,IND,2020,397540.2,USD (1),aqf,FAO global trade +India,IND,2021,503811.3,USD (1),aqf,FAO global trade +Indonesia,IDN,2019,6464803,USD (1),aqf,FAO global trade +Indonesia,IDN,2020,5991307.5,USD (1),aqf,FAO global trade +Indonesia,IDN,2021,6648616.7,USD (1),aqf,FAO global trade +Iran (Islamic Republic of),IRN,2019,76688.90000000001,USD (1),aqf,FAO global trade +Iran (Islamic Republic of),IRN,2020,1318366.3,USD (1),aqf,FAO global trade +Iran (Islamic Republic of),IRN,2021,60844,USD (1),aqf,FAO global trade +Ireland,IRL,2019,0,USD (1),aqf,FAO global trade +Ireland,IRL,2020,16955.9,USD (1),aqf,FAO global trade +Ireland,IRL,2021,11.799999999999999,USD (1),aqf,FAO global trade +Israel,ISR,2019,93000,USD (1),aqf,FAO global trade +Israel,ISR,2020,0,USD (1),aqf,FAO global trade +Israel,ISR,2021,183000,USD (1),aqf,FAO global trade +Italy,ITA,2019,347236.39999999997,USD (1),aqf,FAO global trade +Italy,ITA,2020,233300.2,USD (1),aqf,FAO global trade +Italy,ITA,2021,152837.09999999998,USD (1),aqf,FAO global trade +Japan,JPN,2019,218248.5,USD (1),aqf,FAO global trade +Japan,JPN,2020,502915.8,USD (1),aqf,FAO global trade +Japan,JPN,2021,472628,USD (1),aqf,FAO global trade +Kenya,KEN,2019,54729.1,USD (1),aqf,FAO global trade +Kenya,KEN,2020,269947.3,USD (1),aqf,FAO global trade +Kenya,KEN,2021,548765.7999999999,USD (1),aqf,FAO global trade +Kiribati,KIR,2019,96439.5,USD (1),aqf,FAO global trade +Kiribati,KIR,2020,23843.199999999997,USD (1),aqf,FAO global trade +Kiribati,KIR,2021,0,USD (1),aqf,FAO global trade +Lebanon,LBN,2019,0,USD (1),aqf,FAO global trade +Lebanon,LBN,2020,3355,USD (1),aqf,FAO global trade +Lebanon,LBN,2021,2449,USD (1),aqf,FAO global trade +Libya,LBY,2019,0,USD (1),aqf,FAO global trade +Libya,LBY,2020,243.2,USD (1),aqf,FAO global trade +Libya,LBY,2021,0,USD (1),aqf,FAO global trade +Lithuania,LTU,2019,208342,USD (1),aqf,FAO global trade +Lithuania,LTU,2020,143927,USD (1),aqf,FAO global trade +Lithuania,LTU,2021,195897.3,USD (1),aqf,FAO global trade +Madagascar,MDG,2019,3959.3999999999996,USD (1),aqf,FAO global trade +Madagascar,MDG,2020,0,USD (1),aqf,FAO global trade +Madagascar,MDG,2021,1134.7,USD (1),aqf,FAO global trade +Malawi,MWI,2019,109996.29999999999,USD (1),aqf,FAO global trade +Malawi,MWI,2020,0,USD (1),aqf,FAO global trade +Malawi,MWI,2021,228636.80000000002,USD (1),aqf,FAO global trade +Malaysia,MYS,2019,871983.1,USD (1),aqf,FAO global trade +Malaysia,MYS,2020,641024.9,USD (1),aqf,FAO global trade +Malaysia,MYS,2021,721907.4,USD (1),aqf,FAO global trade +Maldives,MDV,2019,430068.10000000003,USD (1),aqf,FAO global trade +Maldives,MDV,2020,1313435.3,USD (1),aqf,FAO global trade +Maldives,MDV,2021,457034.8,USD (1),aqf,FAO global trade +Marshall Islands,MHL,2019,187885.9,USD (1),aqf,FAO global trade +Marshall Islands,MHL,2020,272316.3,USD (1),aqf,FAO global trade +Marshall Islands,MHL,2021,587449.1,USD (1),aqf,FAO global trade +Mauritius,MUS,2019,62791.6,USD (1),aqf,FAO global trade +Mauritius,MUS,2020,4380.200000000001,USD (1),aqf,FAO global trade +Mauritius,MUS,2021,8301.5,USD (1),aqf,FAO global trade +Mexico,MEX,2019,46448,USD (1),aqf,FAO global trade +Mexico,MEX,2020,120013,USD (1),aqf,FAO global trade +Mexico,MEX,2021,111834,USD (1),aqf,FAO global trade +Micronesia (Federated States of),FSM,2019,105546.8,USD (1),aqf,FAO global trade +Micronesia (Federated States of),FSM,2020,26043.7,USD (1),aqf,FAO global trade +Micronesia (Federated States of),FSM,2021,152139.3,USD (1),aqf,FAO global trade +Montserrat,MSR,2019,0,USD (1),aqf,FAO global trade +Montserrat,MSR,2020,0,USD (1),aqf,FAO global trade +Montserrat,MSR,2021,42.1,USD (1),aqf,FAO global trade +Mozambique,MOZ,2019,3235.5,USD (1),aqf,FAO global trade +Mozambique,MOZ,2020,424.90000000000003,USD (1),aqf,FAO global trade +Mozambique,MOZ,2021,0,USD (1),aqf,FAO global trade +Myanmar,MMR,2019,5531.5,USD (1),aqf,FAO global trade +Myanmar,MMR,2020,4652.9000000000005,USD (1),aqf,FAO global trade +Myanmar,MMR,2021,2375,USD (1),aqf,FAO global trade +Nepal,NPL,2019,671.4,USD (1),aqf,FAO global trade +Nepal,NPL,2020,0,USD (1),aqf,FAO global trade +Nepal,NPL,2021,0,USD (1),aqf,FAO global trade +Netherlands (Kingdom of the),NLD,2019,11593593.7,USD (1),aqf,FAO global trade +Netherlands (Kingdom of the),NLD,2020,13642807.2,USD (1),aqf,FAO global trade +Netherlands (Kingdom of the),NLD,2021,23820730.4,USD (1),aqf,FAO global trade +New Caledonia,NCL,2019,170057.2,USD (1),aqf,FAO global trade +New Caledonia,NCL,2020,114735.1,USD (1),aqf,FAO global trade +New Caledonia,NCL,2021,185340,USD (1),aqf,FAO global trade +New Zealand,NZL,2019,31942.3,USD (1),aqf,FAO global trade +New Zealand,NZL,2020,10674.4,USD (1),aqf,FAO global trade +New Zealand,NZL,2021,0,USD (1),aqf,FAO global trade +Nicaragua,NIC,2019,2851238.0000000005,USD (1),aqf,FAO global trade +Nicaragua,NIC,2020,19112.5,USD (1),aqf,FAO global trade +Nicaragua,NIC,2021,22017.5,USD (1),aqf,FAO global trade +Nigeria,NGA,2019,0,USD (1),aqf,FAO global trade +Nigeria,NGA,2020,18536.100000000002,USD (1),aqf,FAO global trade +Nigeria,NGA,2021,0,USD (1),aqf,FAO global trade +Norway,NOR,2019,0,USD (1),aqf,FAO global trade +Norway,NOR,2020,0,USD (1),aqf,FAO global trade +Norway,NOR,2021,2344.6,USD (1),aqf,FAO global trade +Oman,OMN,2019,330.3,USD (1),aqf,FAO global trade +Oman,OMN,2020,1472,USD (1),aqf,FAO global trade +Oman,OMN,2021,0,USD (1),aqf,FAO global trade +Pakistan,PAK,2019,6191.2,USD (1),aqf,FAO global trade +Pakistan,PAK,2020,0,USD (1),aqf,FAO global trade +Pakistan,PAK,2021,0,USD (1),aqf,FAO global trade +Palau,PLW,2019,152737,USD (1),aqf,FAO global trade +Palau,PLW,2020,201624.1,USD (1),aqf,FAO global trade +Palau,PLW,2021,331843.10000000003,USD (1),aqf,FAO global trade +Papua New Guinea,PNG,2019,0,USD (1),aqf,FAO global trade +Papua New Guinea,PNG,2020,0,USD (1),aqf,FAO global trade +Papua New Guinea,PNG,2021,1964.6,USD (1),aqf,FAO global trade +Peru,PER,2019,1470.8000000000002,USD (1),aqf,FAO global trade +Peru,PER,2020,0,USD (1),aqf,FAO global trade +Peru,PER,2021,0,USD (1),aqf,FAO global trade +Philippines,PHL,2019,6186341,USD (1),aqf,FAO global trade +Philippines,PHL,2020,3971363,USD (1),aqf,FAO global trade +Philippines,PHL,2021,5813332,USD (1),aqf,FAO global trade +Poland,POL,2019,2514.5,USD (1),aqf,FAO global trade +Poland,POL,2020,2904,USD (1),aqf,FAO global trade +Poland,POL,2021,1133.1,USD (1),aqf,FAO global trade +Portugal,PRT,2019,784971.1,USD (1),aqf,FAO global trade +Portugal,PRT,2020,976874.5,USD (1),aqf,FAO global trade +Portugal,PRT,2021,2080256.1,USD (1),aqf,FAO global trade +Republic of Korea,KOR,2019,3351,USD (1),aqf,FAO global trade +Republic of Korea,KOR,2020,10150,USD (1),aqf,FAO global trade +Republic of Korea,KOR,2021,41224,USD (1),aqf,FAO global trade +Romania,ROU,2019,214145.40000000002,USD (1),aqf,FAO global trade +Romania,ROU,2020,45596.5,USD (1),aqf,FAO global trade +Romania,ROU,2021,0,USD (1),aqf,FAO global trade +Russian Federation,RUS,2019,3000,USD (1),aqf,FAO global trade +Russian Federation,RUS,2020,0,USD (1),aqf,FAO global trade +Russian Federation,RUS,2021,0,USD (1),aqf,FAO global trade +Singapore,SGP,2019,434514.4,USD (1),aqf,FAO global trade +Singapore,SGP,2020,194320.1,USD (1),aqf,FAO global trade +Singapore,SGP,2021,208018.19999999998,USD (1),aqf,FAO global trade +Somalia,SOM,2019,2310.5,USD (1),aqf,FAO global trade +Somalia,SOM,2020,41980.4,USD (1),aqf,FAO global trade +Somalia,SOM,2021,153682,USD (1),aqf,FAO global trade +South Africa,ZAF,2019,78087.20000000001,USD (1),aqf,FAO global trade +South Africa,ZAF,2020,11897.2,USD (1),aqf,FAO global trade +South Africa,ZAF,2021,28665.1,USD (1),aqf,FAO global trade +Spain,ESP,2019,31753369.7,USD (1),aqf,FAO global trade +Spain,ESP,2020,33032568.500000004,USD (1),aqf,FAO global trade +Spain,ESP,2021,34872957.1,USD (1),aqf,FAO global trade +Sri Lanka,LKA,2019,6521245.8,USD (1),aqf,FAO global trade +Sri Lanka,LKA,2020,5102162.2,USD (1),aqf,FAO global trade +Sri Lanka,LKA,2021,8730397.7,USD (1),aqf,FAO global trade +Sudan,SDN,2019,0,USD (1),aqf,FAO global trade +Sudan,SDN,2020,38.800000000000004,USD (1),aqf,FAO global trade +Sudan,SDN,2021,21773.2,USD (1),aqf,FAO global trade +Suriname,SUR,2019,16468.9,USD (1),aqf,FAO global trade +Suriname,SUR,2020,26911.1,USD (1),aqf,FAO global trade +Suriname,SUR,2021,48964.8,USD (1),aqf,FAO global trade +Sweden,SWE,2019,41586.3,USD (1),aqf,FAO global trade +Sweden,SWE,2020,39542.899999999994,USD (1),aqf,FAO global trade +Sweden,SWE,2021,57450.4,USD (1),aqf,FAO global trade +Switzerland,CHE,2019,0,USD (1),aqf,FAO global trade +Switzerland,CHE,2020,615.5,USD (1),aqf,FAO global trade +Switzerland,CHE,2021,0,USD (1),aqf,FAO global trade +Syrian Arab Republic,SYR,2019,5794.7,USD (1),aqf,FAO global trade +Syrian Arab Republic,SYR,2020,0,USD (1),aqf,FAO global trade +Syrian Arab Republic,SYR,2021,35933,USD (1),aqf,FAO global trade +Taiwan Province of China,TWN,2019,2626208.6,USD (1),aqf,FAO global trade +Taiwan Province of China,TWN,2020,2134484.1,USD (1),aqf,FAO global trade +Taiwan Province of China,TWN,2021,2300741.1,USD (1),aqf,FAO global trade +Thailand,THA,2019,14258050.6,USD (1),aqf,FAO global trade +Thailand,THA,2020,9467955.1,USD (1),aqf,FAO global trade +Thailand,THA,2021,10415681.4,USD (1),aqf,FAO global trade +Tonga,TON,2019,98676.5,USD (1),aqf,FAO global trade +Tonga,TON,2020,62785.9,USD (1),aqf,FAO global trade +Tonga,TON,2021,256437.8,USD (1),aqf,FAO global trade +Trinidad and Tobago,TTO,2019,122,USD (1),aqf,FAO global trade +Trinidad and Tobago,TTO,2020,2546.9,USD (1),aqf,FAO global trade +Trinidad and Tobago,TTO,2021,1445.5,USD (1),aqf,FAO global trade +Türkiye,TUR,2019,33206,USD (1),aqf,FAO global trade +Türkiye,TUR,2020,5518,USD (1),aqf,FAO global trade +Türkiye,TUR,2021,76370,USD (1),aqf,FAO global trade +Uganda,UGA,2019,897.8000000000001,USD (1),aqf,FAO global trade +Uganda,UGA,2020,0,USD (1),aqf,FAO global trade +Uganda,UGA,2021,0,USD (1),aqf,FAO global trade +United Arab Emirates,ARE,2019,236564,USD (1),aqf,FAO global trade +United Arab Emirates,ARE,2020,24634.4,USD (1),aqf,FAO global trade +United Arab Emirates,ARE,2021,0,USD (1),aqf,FAO global trade +United Kingdom of Great Britain and Northern Ireland,GBR,2019,1499324,USD (1),aqf,FAO global trade +United Kingdom of Great Britain and Northern Ireland,GBR,2020,2013629,USD (1),aqf,FAO global trade +United Kingdom of Great Britain and Northern Ireland,GBR,2021,253856.1,USD (1),aqf,FAO global trade +United Republic of Tanzania,TZA,2019,17568,USD (1),aqf,FAO global trade +United Republic of Tanzania,TZA,2020,52587.299999999996,USD (1),aqf,FAO global trade +United Republic of Tanzania,TZA,2021,0,USD (1),aqf,FAO global trade +United States of America,USA,2019,4495444,USD (1),aqf,FAO global trade +United States of America,USA,2020,2921557,USD (1),aqf,FAO global trade +United States of America,USA,2021,2688922,USD (1),aqf,FAO global trade +Vanuatu,VUT,2019,0,USD (1),aqf,FAO global trade +Vanuatu,VUT,2020,0,USD (1),aqf,FAO global trade +Vanuatu,VUT,2021,341.40000000000003,USD (1),aqf,FAO global trade +Venezuela (Bolivarian Republic of),VEN,2019,6171.2,USD (1),aqf,FAO global trade +Venezuela (Bolivarian Republic of),VEN,2020,1910.9,USD (1),aqf,FAO global trade +Venezuela (Bolivarian Republic of),VEN,2021,3283.2,USD (1),aqf,FAO global trade +Viet Nam,VNM,2019,1194305,USD (1),aqf,FAO global trade +Viet Nam,VNM,2020,129938,USD (1),aqf,FAO global trade +Viet Nam,VNM,2021,242640,USD (1),aqf,FAO global trade +Zambia,ZMB,2019,0,USD (1),aqf,FAO global trade +Zambia,ZMB,2020,0,USD (1),aqf,FAO global trade +Zambia,ZMB,2021,967.7,USD (1),aqf,FAO global trade +Zimbabwe,ZWE,2019,293142.80000000005,USD (1),aqf,FAO global trade +Zimbabwe,ZWE,2020,367659.4,USD (1),aqf,FAO global trade +Zimbabwe,ZWE,2021,114458.1,USD (1),aqf,FAO global trade diff --git a/workflow/R/fao_query_data_tidy.R b/workflow/R/fao_query_data_tidy.R index a220d1f1..577240de 100644 --- a/workflow/R/fao_query_data_tidy.R +++ b/workflow/R/fao_query_data_tidy.R @@ -29,17 +29,19 @@ fao_query_data_tidy <- function(fao, initial_data_year, last_data_year, sub_N = values_to = "value") %>% # clean up year column (currently in the form of xYYYY) mutate(year = str_remove_all(year, pattern = "x")) - - - # pivot all of the flag columns - fao_flags <- fao %>% + + + # pivot all of the flag columns + fao_flags <- fao %>% select(-c(paste0("x", initial_data_year:last_data_year))) %>% pivot_longer(cols = ends_with("_flag"), names_to = "flag_year", values_to = "flag") %>% # make year column using the year label from the flags for joining mutate(year = str_remove(flag_year, "_flag")) %>% - select(year, flag, row_id) + # clean up year column (currently in the form of xYYYY) + mutate(year = str_remove_all(year, pattern = "x")) %>% + select(year, flag, row_id) # combine flag and row id fao_new <- fao_values %>%