Readr
Summary

Instruction

That helped, but now we don't have column names and we want them. We can change the incorrect column names (i.e., the first row of data) with colnames(). Or we could use the col_names argument in a different way. Instead of simply declaring that our data has no column names – which we by setting col_names to FALSE – we can provide a list of the column names we want to use. We do this by placing them in a vector with the c() function. The example below shows us specifying column names for our student data:

read_csv("data/winters_students.csv", skip = 5,
    col_names = c(
      "first_name", "last_name",
      "email", "age", "phone_number"))

Exercise

Once again, read data/plants.csv into the plants variable. Skip the first two rows, and provide plant_name, country, and age as the column names.

Stuck? Here's a hint!

Type:

plants <- read_csv("data/plants.csv", skip = 2, 
  col_names = c("plant_name", "country", "age"))