From e64e5ab5b6c2833d7037f66e3f71d4f532adb872 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 24 Nov 2024 21:57:40 +0100 Subject: [PATCH] better example --- R/data_arrange.R | 7 +++++-- man/data_arrange.Rd | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/R/data_arrange.R b/R/data_arrange.R index a5745d0c5..eee103ea3 100644 --- a/R/data_arrange.R +++ b/R/data_arrange.R @@ -24,8 +24,11 @@ #' # Arrange in decreasing order #' data_arrange(head(mtcars), "-carb") #' -#' # arrange several variables, grouped by another one -#' data_arrange(head(mtcars), c("gear", "carb"), by = "cyl") +#' # compare: arrange variables vs. arrange variable within groups +#' set.seed(123) +#' x <- iris[sample(seq_len(nrow(iris)), 10, replace = TRUE), c("Sepal.Width", "Species")] +#' data_arrange(x, c("Sepal.Width", "Species")) +#' data_arrange(x, "Sepal.Width", by = "Species") #' #' # Throw an error if one of the variables specified doesn't exist #' try(data_arrange(head(mtcars), c("gear", "foo"), safe = FALSE)) diff --git a/man/data_arrange.Rd b/man/data_arrange.Rd index 414533659..616f3f9fb 100644 --- a/man/data_arrange.Rd +++ b/man/data_arrange.Rd @@ -40,8 +40,11 @@ data_arrange(head(mtcars), c("gear", "carb")) # Arrange in decreasing order data_arrange(head(mtcars), "-carb") -# arrange several variables, grouped by another one -data_arrange(head(mtcars), c("gear", "carb"), by = "cyl") +# compare: arrange variables vs. arrange variable within groups +set.seed(123) +x <- iris[sample(seq_len(nrow(iris)), 10, replace = TRUE), c("Sepal.Width", "Species")] +data_arrange(x, c("Sepal.Width", "Species")) +data_arrange(x, "Sepal.Width", by = "Species") # Throw an error if one of the variables specified doesn't exist try(data_arrange(head(mtcars), c("gear", "foo"), safe = FALSE))