0
0
R Programmingprogramming~10 mins

arrange() for sorting 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 sort the data frame df by the column age in ascending order using arrange().

R Programming
library(dplyr)
sorted_df <- df %>% arrange([1])
print(sorted_df)
Drag options to blanks, or click blank then click option'
Aage
Bdesc(age)
Cage()
Dsort(age)
Attempts:
3 left
💡 Hint
Common Mistakes
Using desc(age) which sorts in descending order.
Using age() which is not a valid function here.
2fill in blank
medium

Complete the code to sort the data frame df by the column score in descending order using arrange().

R Programming
library(dplyr)
sorted_df <- df %>% arrange([1])
print(sorted_df)
Drag options to blanks, or click blank then click option'
Ascore
Bscore()
Cdesc(score)
Dsort(score)
Attempts:
3 left
💡 Hint
Common Mistakes
Using just score which sorts ascending.
Using score() which is invalid.
3fill in blank
hard

Fix the error in the code to correctly sort df by height in ascending order.

R Programming
library(dplyr)
sorted_df <- df %>% arrange([1])
print(sorted_df)
Drag options to blanks, or click blank then click option'
Aheight
Bheight()
Cdesc(height)
Dsort(height)
Attempts:
3 left
💡 Hint
Common Mistakes
Using height() which is not valid syntax.
Using desc(height) which sorts descending.
4fill in blank
hard

Fill both blanks to sort df first by age ascending, then by score descending.

R Programming
library(dplyr)
sorted_df <- df %>% arrange([1], [2])
print(sorted_df)
Drag options to blanks, or click blank then click option'
Aage
Bdesc(score)
Cscore
Ddesc(age)
Attempts:
3 left
💡 Hint
Common Mistakes
Using score instead of desc(score) for descending order.
Using desc(age) which reverses the first sort.
5fill in blank
hard

Fill all three blanks to sort df by gender ascending, then age descending, then score ascending.

R Programming
library(dplyr)
sorted_df <- df %>% arrange([1], [2], [3])
print(sorted_df)
Drag options to blanks, or click blank then click option'
Agender
Bdesc(age)
Cscore
Ddesc(score)
Attempts:
3 left
💡 Hint
Common Mistakes
Using desc(score) instead of score for ascending order.
Not using desc() for age to get descending order.