Parsing strings into variables
A common use for str_split()
is to pull apart raw string data into more useful variables. In this exercise you'll start by pulling apart a date range, something like "23.01.2017 - 29.01.2017"
, into separate variables for the start of the range, "23.01.2017"
, and the end of the range, "29.01.2017"
.
Remember, if the simplify
argument is FALSE
(the default) you'll get back a list of the same length as that of the input vector. More commonly, you'll want to pull out the first piece (or second piece etc.) from every element, which is easier if you specify simplify = TRUE
and get a matrix as output. You'll explore both of these output types in this exercise.
Diese Übung ist Teil des Kurses
String Manipulation with stringr in R
Interaktive Übung
Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.
# Some date data
date_ranges <- c("23.01.2017 - 29.01.2017", "30.01.2017 - 06.02.2017")
# Split dates using " - "
split_dates <- ___
split_dates