Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sort_df() and decreasing order? #73

Open
Deleetdk opened this issue Nov 26, 2015 · 0 comments
Open

sort_df() and decreasing order? #73

Deleetdk opened this issue Nov 26, 2015 · 0 comments

Comments

@Deleetdk
Copy link

It appears that sort_df() does not have an option for using variables in decreasing order, which is in sort() in base.

This code should do the trick.

sort_df = function (data, vars = names(data), decreasing = F)
{
  if (length(vars) == 0 || is.null(vars))
    return(data)
  data[do.call("order", list(what = data[, vars, drop = FALSE], decreasing = decreasing)), , drop = FALSE]
}

Tested with:

sort_df(iris, "Sepal.Length")
sort_df(iris, "Sepal.Length", decreasing = T)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant