Which command sorts the numeric vector x in descending order using only base R?
- FALSE.
sort(x)sorts in ascending order by default. - TRUE.
sort(x, decreasing = TRUE)correctly sortsxin descending order. - FALSE.
sort(x, reverse = TRUE)is not a valid argument in thesortfunction. - FALSE.
sort(-x)sorts the negated values ofx, which does not yield the correct descending order ofx. - FALSE.
order(x, decreasing = TRUE)returns the indices that would sortxin descending order, not the sorted vector itself.
Suppose you have
{. .cell-code} y <- data.frame(x1 = 1:10, x2 = c(-1, 1), x3 = runif(10))
Which of the following commands sort the rows by x3 in ascending order (same result, possibly using different syntaxes)?
- TRUE.
arrange(y, x3)sorts the data frameyby the columnx3in ascending order. - TRUE.
arrange(y, +x3)also sortsybyx3in ascending order; the+sign does not change the order. - TRUE.
y[order(y$x3, decreasing = FALSE), ]sorts the rows ofybyx3in ascending order. - FALSE.
y[order(x3), ]will result in an error becausex3is not defined in the global environment; it needs to be referenced asy$x3. - FALSE.
arrange(y, -x3)sortsybyx3in descending order, which is not what we want.