NY.GNS.ICTR.CD_table1 <- NY.GNS.ICTR.CD |>
left_join(NE.GDI.TOTL.CD |> select(iso2c, year, NE.GDI.TOTL.CD = value), by = c("iso2c", "year")) |>
left_join(NY.ADJ.DKAP.CD |> select(iso2c, year, NY.ADJ.DKAP.CD = value), by = c("iso2c", "year")) |>
left_join(iso2c, by = "iso2c") |>
filter(year == 2017) |>
mutate(`Net Saving (Bn)` = value - NY.ADJ.DKAP.CD,
`Net Investment (Bn)` = NE.GDI.TOTL.CD - NY.ADJ.DKAP.CD,
`Current Account (Bn)` = `Net Saving (Bn)` - `Net Investment (Bn)`,
`Current Account (% Net Investment)` = round(100*(`Net Saving (Bn)`/`Net Investment (Bn)`-1), 2)) |>
select(iso2c, Iso2c, `Net Saving (Bn)`, `Net Investment (Bn)`, `Current Account (Bn)`, `Current Account (% Net Investment)`) |>
arrange(-`Net Saving (Bn)`) %>%
mutate_at(vars(`Net Investment (Bn)`, `Net Saving (Bn)`, `Current Account (Bn)`), funs(paste0("$ ", round(./10^9))))
save(NY.GNS.ICTR.CD_table1, file = "NY.GNS.ICTR.CD_table1.RData")
NY.GNS.ICTR.CD_table1 %>%
{if (is_html_output()) datatable(., filter = 'top', rownames = F) else .}