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).
Make a new code chunk (CTRL
+Alt
+I
on Windows, Cmd
+ Option
+ I
on a Mac). In that chuck, load tidyverse
and magrittr
libraries.
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).
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]
As you can see if you open it, this file is very large and unwieldy. Clean it up by:
GDP (constant 2010 US$)
). Remove all the unnecessary rows and columns.What does your plot show? Why?
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.
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.