Practice: Parsing a Vector

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

  1. What are the most important arguments to locale()?

  2. What happens if you try and set decimal_mark and grouping_mark to the same character? What happens to the default value of grouping_mark when you set decimal_mark to ","? What happens to the default value of decimal_mark when you set the grouping_mark to "."?

  3. I didn't discuss the date_format and time_format options to locale(). What do they do? Construct an example that shows when they might be useful.

  4. If you live outside the US, create a new locale object that encapsulates the settings for the types of file you read most commonly.

  5. What's the difference between read_csv() and read_csv2()?

  6. What are the most common encodings used in Europe? What are the most common encodings used in Asia? Do some googling to find out.

  7. 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
Creative Commons License This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 3.0 License.

Last modified: Monday, January 9, 2023, 3:50 PM