Code Studio: Parse Messy Numbers (readr)
Real data arrives messy. Parsing a Vector shows readr's parse_number(), which pulls the number out of text like "$1,234.50" or "45%".
The program reads several lines of messy values, one per line. Using parse_number():
- Convert every line to a number.
- Print how many values there are, their total and their mean, the total and mean rounded to 2 decimal places:
Count: 3 Total: 1291.5 Mean: 430.5
What does parse_number() do with the text "about 12 people"? And with a line that has no number at all?
Real data arrives messy. Parsing a Vector shows readr's parse_number(), which pulls the number out of text like "$1,234.50" or "45%".
The program reads several lines of messy values, one per line. Using parse_number():
- Convert every line to a number.
- Print how many values there are, their total and their mean, the total and mean rounded to 2 decimal places:
Count: 3 Total: 1291.5 Mean: 430.5
What does parse_number() do with the text "about 12 people"? And with a line that has no number at all?