Description Usage Arguments Details Examples
This is a useful function to control the order 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.
1 |
order_by |
a vector to order_by |
call |
a function call to a window function, where the first argument is the vector being operated on |
This function works by changing the call
to instead call
with_order
with the appropriate arguments.
1 2 3 4 5 6 7 8 9 10 11 12 13 | 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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.