0
0
R Programmingprogramming~10 mins

separate and unite in R Programming - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to separate the 'date' column into 'year', 'month', and 'day'.

R Programming
library(tidyr)
data <- data.frame(date = c('2023-06-01', '2023-06-02'))
separated <- separate(data, col = [1], into = c('year', 'month', 'day'), sep = '-')
Drag options to blanks, or click blank then click option'
Aday
Byear
Cmonth
Ddate
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong column name like 'year' instead of 'date'.
Forgetting to specify the column to separate.
2fill in blank
medium

Complete the code to unite the 'year', 'month', and 'day' columns into a single 'date' column separated by '-'.

R Programming
library(tidyr)
data <- data.frame(year = c('2023', '2023'), month = c('06', '06'), day = c('01', '02'))
united <- unite(data, col = [1], year, month, day, sep = '-')
Drag options to blanks, or click blank then click option'
Ayear
Bday
Cdate
Dmonth
Attempts:
3 left
💡 Hint
Common Mistakes
Using an existing column name like 'year' as the new column name.
Not specifying the new column name correctly.
3fill in blank
hard

Fix the error in the code to separate the 'datetime' column into 'date' and 'time'.

R Programming
library(tidyr)
data <- data.frame(datetime = c('2023-06-01 12:00', '2023-06-02 13:30'))
separated <- separate(data, col = [1], into = c('date', 'time'), sep = ' ')
Drag options to blanks, or click blank then click option'
Adatetime
Bdate
Ctime
Ddatetime_col
Attempts:
3 left
💡 Hint
Common Mistakes
Using a column name that does not exist in the data frame.
Misspelling the column name.
4fill in blank
hard

Fill both blanks to separate the 'full_name' column into 'first' and 'last' names using space as separator.

R Programming
library(tidyr)
data <- data.frame(full_name = c('John Doe', 'Jane Smith'))
separated <- separate(data, col = [1], into = c([2], 'last'), sep = ' ')
Drag options to blanks, or click blank then click option'
Afull_name
Bfirst
Cname
Dlast_name
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong column names for splitting.
Mixing up the order of new column names.
5fill in blank
hard

Fill all three blanks to unite 'city', 'state', and 'zip' columns into 'address' separated by commas.

R Programming
library(tidyr)
data <- data.frame(city = c('Austin', 'Boston'), state = c('TX', 'MA'), zip = c('73301', '02101'))
united <- unite(data, col = [1], [2], [3], sep = ', ')
Drag options to blanks, or click blank then click option'
Aaddress
Bcity
Cstate
Dzip
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong column names or missing one of the columns.
Not specifying the new column name correctly.