Bắt đầu ngayBắt đầu miễn phí

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.

Bài tập này là một phần của khóa học

String Manipulation with stringr in R

Xem khóa học

Bài tập tương tác thực hành trực tiếp

Hãy thử làm bài tập này bằng cách hoàn thành đoạn mã mẫu này.

# 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
Chỉnh sửa và Chạy Mã