Session Ready
Exercise

Cast a column to a number

In the video, we saw a good workflow for parsing columns using readr:

  • Use parse_number() to practice, then
  • Use col_number() to cast.

But sometimes you'll need to start with casting, then diagnose parsing problems using a new readr function called problems(). Using problems() on a result of read_csv() will show you the rows and columns where parsing error occurred, what the parser expected to find (for example, a number), and the actual value that caused the parsing error.

Let's practice this with "desserts.csv", which includes data about the judges' ranks for each baker in the technical challenge, for every episode.

Instructions 1/3
undefined XP
  • 1

    Add another line to cols() to cast the technical column as a number. You will get a parsing error! Read the red text carefully.

    • 2

      Pass the desserts tibble to the problems() function. Which values were not parsed (take a look at the actual column)?

    • 3

      Adapt the code so that the value that read_csv() couldn't parse would instead be read as missing (think back to chapter 1!)