dat <- data.frame(x = c(5, 2, 5, 5, 7, 2),
y = c(1, 6, 2, 3, 2, 3),
z = c(2, 1, 6, 3, 7, 4))
# Example 1: Sort data frame 'dat' by "x" in increasing order
df.sort(dat, x)
# Example 2: Sort data frame 'dat' by "x" in decreasing order
df.sort(dat, x, decreasing = TRUE)
# Example 3: Sort data frame 'dat' by "x" and "y" in increasing order
df.sort(dat, x, y)
# Example 4: Sort data frame 'dat' by "x" and "y" in decreasing order
df.sort(dat, x, y, decreasing = TRUE)
Run the code above in your browser using DataLab