Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong column name like 'year' instead of 'date'.
Forgetting to specify the column to separate.
✗ Incorrect
The 'separate' function needs the name of the column to split, which is 'date' here.
2fill in blank
mediumComplete 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'
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.
✗ Incorrect
The 'unite' function needs the name of the new column to create, which is 'date' here.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a column name that does not exist in the data frame.
Misspelling the column name.
✗ Incorrect
The 'separate' function requires the exact column name to split, which is 'datetime'.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong column names for splitting.
Mixing up the order of new column names.
✗ Incorrect
The first blank is the column to split: 'full_name'. The second blank is the first new column name: 'first'.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong column names or missing one of the columns.
Not specifying the new column name correctly.
✗ Incorrect
The first blank is the new column name 'address'. The next blanks are the columns to unite: 'city' and 'state'. The last column 'zip' is already in the data frame and will be united automatically.