Complete the code to sort the data frame df by the column age in ascending order using arrange().
library(dplyr) sorted_df <- df %>% arrange([1]) print(sorted_df)
desc(age) which sorts in descending order.age() which is not a valid function here.The arrange() function sorts the data frame by the specified column. Using age sorts it in ascending order.
Complete the code to sort the data frame df by the column score in descending order using arrange().
library(dplyr) sorted_df <- df %>% arrange([1]) print(sorted_df)
score which sorts ascending.score() which is invalid.To sort in descending order, wrap the column name with desc() inside arrange().
Fix the error in the code to correctly sort df by height in ascending order.
library(dplyr) sorted_df <- df %>% arrange([1]) print(sorted_df)
height() which is not valid syntax.desc(height) which sorts descending.The correct way to sort ascending is to use the column name directly without parentheses or functions.
Fill both blanks to sort df first by age ascending, then by score descending.
library(dplyr) sorted_df <- df %>% arrange([1], [2]) print(sorted_df)
score instead of desc(score) for descending order.desc(age) which reverses the first sort.Use age for ascending sort first, then desc(score) for descending sort second.
Fill all three blanks to sort df by gender ascending, then age descending, then score ascending.
library(dplyr) sorted_df <- df %>% arrange([1], [2], [3]) print(sorted_df)
desc(score) instead of score for ascending order.desc() for age to get descending order.Sort by gender ascending, then age descending using desc(age), then score ascending.