Lec02
More dplyr and basic webscraping.
Announcements
- Homework 0 is now posted in the Calendar section, for which I will do a quick demo of R Markdown.
- If there are ever any minor notes I need to pass along after lecture is over,
such as minor bugs I didn’t notice, I will always post them in the section
titled After-Class Updates. For example, in Lec01 I added a note on the use
of
::inPACKAGE_NAME::FUNCTION_NAME(). - Go over solutions to
Lec01.R, which are at the beginning ofLec02.R.
In-Class
- Slides: An example involving R’s webscraping abilities to collect data
- In-class exercise:
- Packages to install: the
rvestandXMLpackages - Code:
Lec02.R
- Packages to install: the
After-Class Updates
There seems to be some differences in how R reads in webscraped data between Windows and Mac. Windows users
will have a problem with the wp_data$p_need_grant variable, which gets read as a character vector and not a numerical variable.
The solution is to replace lines 122-126 in Lec02.R from
wp_data <- wp_data %>%
mutate(
comp_fee = currency_to_numeric(comp_fee),
ave_no_need_grant = currency_to_numeric(ave_no_need_grant)
)
to
wp_data <- wp_data %>%
mutate(
comp_fee = currency_to_numeric(comp_fee),
ave_no_need_grant = currency_to_numeric(ave_no_need_grant),
p_need_grant = currency_to_numeric(ave_no_need_grant)
)
i.e. use the currency_to_numeric() function to convert on p_need_grant as well. Lec02.R on GitHub has now been updated to reflect this change.