0
0
R Programmingprogramming~10 mins

Why dplyr simplifies data wrangling in R Programming - Test Your Understanding

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

Complete the code to select the column 'mpg' from the mtcars dataset.

R Programming
library(dplyr)
result <- mtcars %>% select([1])
print(result)
Drag options to blanks, or click blank then click option'
Ampg
Bcyl
Cgear
Dhp
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a column name that does not exist in the dataset.
2fill in blank
medium

Complete the code to filter rows where 'cyl' equals 6.

R Programming
library(dplyr)
result <- mtcars %>% filter([1] == 6)
print(result)
Drag options to blanks, or click blank then click option'
Ampg
Bcyl
Cgear
Dhp
Attempts:
3 left
💡 Hint
Common Mistakes
Filtering on a wrong column like 'mpg' or 'gear'.
3fill in blank
hard

Fix the error in the code to arrange the dataset by 'hp' in descending order.

R Programming
library(dplyr)
result <- mtcars %>% arrange([1](hp))
print(result)
Drag options to blanks, or click blank then click option'
Aasc
Border
Cdesc
Dsort
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'asc' for descending order or using base R functions like 'order' or 'sort' inside arrange.
4fill in blank
hard

Fill both blanks to create a new column 'power_to_weight' as hp divided by wt.

R Programming
library(dplyr)
result <- mtcars %>% mutate(power_to_weight = [1] / [2])
print(result$power_to_weight)
Drag options to blanks, or click blank then click option'
Ahp
Bmpg
Cwt
Dcyl
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong columns like 'mpg' or 'cyl' in the calculation.
5fill in blank
hard

Fill both blanks to create a summary with average mpg for cars with more than 4 gears.

R Programming
library(dplyr)
summary <- mtcars %>% filter([1] > 4) %>% summarise(avg_mpg = mean([2]))
print(summary)
Drag options to blanks, or click blank then click option'
Agear
Bmpg
Ccyl
Dhp
Attempts:
3 left
💡 Hint
Common Mistakes
Filtering on wrong columns or calculating mean of wrong columns.