0
0
R Programmingprogramming~10 mins

Nesting and unnesting 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 nest the data frame by the 'group' column.

R Programming
library(dplyr)
library(tidyr)
data <- data.frame(group = c('A', 'A', 'B', 'B'), value = 1:4)
nested_data <- data %>% group_by(group) %>% [1](data = c(value))
Drag options to blanks, or click blank then click option'
Anest
Bfilter
Cunnest
Dselect
Attempts:
3 left
💡 Hint
Common Mistakes
Using unnest instead of nest
Using filter or select which do not nest data
2fill in blank
medium

Complete the code to unnest the nested data frame column 'data'.

R Programming
library(tidyr)
nested_data <- tibble(group = c('A', 'B'), data = list(tibble(value = 1:2), tibble(value = 3:4)))
unnested_data <- nested_data %>% [1](data)
Drag options to blanks, or click blank then click option'
Anest
Bsummarise
Cunnest
Dgroup_by
Attempts:
3 left
💡 Hint
Common Mistakes
Using nest instead of unnest
Using group_by or summarise which do not unnest
3fill in blank
hard

Fix the error in the code to correctly nest the data frame by 'category'.

R Programming
library(tidyr)
data <- data.frame(category = c('X', 'X', 'Y'), score = c(10, 20, 30))
nested <- data %>% [1](category, data = c(score))
Drag options to blanks, or click blank then click option'
Anest
Bunnest
Cfilter
Dselect
Attempts:
3 left
💡 Hint
Common Mistakes
Using unnest instead of nest
Using filter or select which do not nest data
4fill in blank
hard

Fill both blanks to nest the data frame by 'team' and nest the 'points' column.

R Programming
library(tidyr)
data <- data.frame(team = c('Red', 'Red', 'Blue'), points = c(5, 7, 8))
nested <- data %>% group_by([1]) %>% [2](data = c(points))
Drag options to blanks, or click blank then click option'
Ateam
Bscore
Cnest
Dunnest
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong column name for grouping
Using unnest instead of nest
5fill in blank
hard

Fill all three blanks to unnest the nested data frame and select the 'group' and 'value' columns.

R Programming
library(tidyr)
nested_data <- tibble(group = c('A', 'B'), data = list(tibble(value = 1:2), tibble(value = 3:4)))
unnested <- nested_data %>% [1](data) %>% select([2], [3])
Drag options to blanks, or click blank then click option'
Aunnest
Bgroup
Cvalue
Dnest
Attempts:
3 left
💡 Hint
Common Mistakes
Using nest instead of unnest
Selecting wrong column names