arrange.tbl_lazy | R Documentation |
This is an method for the dplyr arrange()
generic. It generates
the ORDER BY
clause of the SQL query. It also affects the
window_order()
of windowed expressions in mutate.tbl_lazy()
.
Note that ORDER BY
clauses can not generally appear in subqueries, which
means that you should arrange()
as late as possible in your pipelines.
## S3 method for class 'tbl_lazy'
arrange(.data, ..., .by_group = FALSE)
.data |
A lazy data frame backed by a database query. |
... |
< |
.by_group |
If |
Another tbl_lazy
. Use show_query()
to see the generated
query, and use collect()
to execute the query
and return data to R.
Unlike R, most databases sorts NA
(NULL
s) at the front. You can
can override this behaviour by explicitly sorting on is.na(x)
.
library(dplyr, warn.conflicts = FALSE)
db <- memdb_frame(a = c(3, 4, 1, 2), b = c(5, 1, 2, NA))
db %>% arrange(a) %>% show_query()
# Note that NAs are sorted first
db %>% arrange(b)
# override by sorting on is.na() first
db %>% arrange(is.na(b), b)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.