These exercises provide real-life examples of issues we can encounter when loading a file with different formats for the dates or decimal points. Complete these exercises to prepare yourself for those situations. This exercise does not count toward your grade. It is just for practice!
Exercises
-
What are the most important arguments to
locale()
? -
What happens if you try and set
decimal_mark
andgrouping_mark
to the same character? What happens to the default value ofgrouping_mark
when you setdecimal_mark
to ","? What happens to the default value ofdecimal_mark
when you set thegrouping_mark
to "."? -
I didn't discuss the
date_format
andtime_format
options tolocale()
. What do they do? Construct an example that shows when they might be useful. -
If you live outside the US, create a new locale object that encapsulates the settings for the types of file you read most commonly.
-
What's the difference between
read_csv()
andread_csv2()
? -
What are the most common encodings used in Europe? What are the most common encodings used in Asia? Do some googling to find out.
-
Generate the correct format string to parse each of the following dates and times:
d1 <- "January 1, 2010" d2 <- "2015-Mar-07" d3 <- "06-Jun-2017" d4 <- c("August 19 (2015)", "July 1 (2015)") d5 <- "12/30/14" # Dec 30, 2014 t1 <- "1705" t2 <- "11:15:10.12 PM"
Source: H. Wickham and G. Grolemund, https://r4ds.had.co.nz/data-import.html This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 3.0 License.