Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Summary
13. Exercise 1

Instruction

It's time to recap what we learned about readr.

We learned how to read data from a CSV format to R using read_csv(). We also learned how to handle some errors by skipping lines (using the skip argument) and to handle missing column names (using the col_names argument):

read_csv("data/winters_students.csv", skip = 5, col_names = FALSE)

We can check the column data types of the dataset with the spec() function:

spec(students)

We can investigate problems encountered when reading the file with the problems() function:

problems(students)

We can read general files into R using any kind of delimiting character, thanks to the read_delim() function:

read_delim("data/zoo.csv", delim = "|")

And we can save data in different formats using the write_delim() function:

write_delim(animals, path = "animals.csv", delim = ";")

Let's practice all the know-how we just acquired. Our final report comes from the Hillside Clinic. Let's see what's in it.

Exercise

We have data from the Hillsdale Clinic about patients and the treatments they received. Read data/hospital.csv into the patients variable using read_csv().

Stuck? Here's a hint!

Type:

patients <- read_csv("data/hospital.csv")