Session Ready
Exercise

Cleaning a data frame

In the last exercise, we looked at extracting tables with html_table(). The resulting data frame was pretty clean, but had two problems - first, the column names weren't descriptive, and second, there was an empty row.

In this exercise we're going to look at fixing both of those problems. First, column names. Column names can be cleaned up with the colnames() function. You call it on the object you want to rename, and then assign to that call a vector of new names.

The missing row, meanwhile, can be removed with the subset() function. subset takes an object, and a condition. For example, if you have a data frame df containing a column x, you could run

subset(df, !x == "")

to remove all rows from df consisting of empty strings ("") in the column x.

Instructions
100 XP
  1. Rename the columns of wiki_table to "key" and "value" using colnames().
  2. Remove the empty row from wiki_table using subset(), and assign the result to cleaned_table.
  3. Print cleaned_table.