File: order_by.Rd

package info (click to toggle)
r-cran-dplyr 1.1.4-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,292 kB
  • sloc: cpp: 1,403; sh: 17; makefile: 7
file content (38 lines) | stat: -rw-r--r-- 1,089 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/order-by.R
\name{order_by}
\alias{order_by}
\title{A helper function for ordering window function output}
\usage{
order_by(order_by, call)
}
\arguments{
\item{order_by}{a vector to order_by}

\item{call}{a function call to a window function, where the first argument
is the vector being operated on}
}
\description{
This function makes it possible to control the ordering of window functions
in R that don't have a specific ordering parameter. When translated to SQL
it will modify the order clause of the OVER function.
}
\details{
This function works by changing the \code{call} to instead call
\code{\link[=with_order]{with_order()}} with the appropriate arguments.
}
\examples{
order_by(10:1, cumsum(1:10))
x <- 10:1
y <- 1:10
order_by(x, cumsum(y))

df <- data.frame(year = 2000:2005, value = (0:5) ^ 2)
scrambled <- df[sample(nrow(df)), ]

wrong <- mutate(scrambled, running = cumsum(value))
arrange(wrong, year)

right <- mutate(scrambled, running = order_by(year, cumsum(value)))
arrange(right, year)
}