worldbank: Projects funded by the World Bank

Description Usage Format Examples

Description

From: http://jsonstudio.com/resources/

Usage

1

Format

JSON

Examples

 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
library(dplyr)

# worldbank is a 500 length character vector of JSON
length(worldbank)

# Let's look at top level values
worldbank %>% spread_all %>% glimpse

# Are there any arrays?
worldbank %>% gather_object %>% json_types %>% count(name, type)

# Get the top 10 sectors by funded project in Africa
wb_sectors <- worldbank %>%   # 500 Projects funded by the world bank
  spread_all %>%
  select(project_name, regionname) %>%
  enter_object(majorsector_percent) %>% # Enter the 'sector' object
  gather_array("sector.index") %>%      # Gather the array
  spread_values(sector = jstring(Name)) # Spread the sector name

# Examine the structured data
wb_sectors %>% glimpse

# Get the top 10 sectors by funded project in Africa
wb_sectors %>%
  filter(regionname == "Africa") %>% # Filter to just Africa
  count(sector) %>%              # Count by sector
  arrange(desc(n)) %>%           # Arrange descending
  top_n(10)                      # Take the top 10

jeremystan/tidyjson documentation built on May 17, 2017, 6:14 p.m.