1. Start a new Rmd document by going to File-->New File-->R Markdown--OK. Save this document under the name yourname_hw6.Rmd. Delete the template Rmarkdown text and chunks (everything starting with ##R Markdown).

  2. Make a new code chunk (CTRL+Alt+I on Windows, Cmd + Option + I on a Mac). In that chuck, load tidyverse and magrittr libraries.

  3. Download the World Development Indicators Data from the World Bank. Click on CSV download under Bulk Downloads. The file is quite large, do give it some time. The file you need is WDIdata.csv (feel free to delete the rest).

  4. To open the file WDIdata.csv, make sure to set the directory by navigating to the correct directory (in the bottom right-hand side pane under File click on \(\dots\)), and setting it as your working directory (More–>Set As Working Directory). Then use the following code to read it the data. Also check to make sure that your Knit directory is set to the same directory (Click on the downward arrow next to Knit, then Knit Directory–>Current Working Directory).

d<-read_csv("WDIData.csv", col_names=T)
## Warning: Missing column names filled in: 'X66' [66]
  1. As you can see if you open it, this file is very large and unwieldy. Clean it up by:

    1. Extracting just the data on GDP (GDP (constant 2010 US$)). Remove all the unnecessary rows and columns.
    2. Transform the data from wide to long form.
    3. To check your work, plot Canada’s GDP by year.
  2. What does your plot show? Why?

  3. Edit the code from Q5, so as to extract GDP and Foreign direct investment, net inflows (% of GDP). Use pivot_wider and/or pivot_longer functions to transform these data into long format (i.e., country-years as rows; country names, year, GDP and FDI as columns). Print the first ten rows of resulting data (mydata[1:10,]) to show your work.

  4. Knit the RMarkdown file (press the “Knit” button above) and read through the corresponding html file.

For the submission: submit your solution in an R Markdown file and (just for insurance) submit the corresponding html file with it.