Description Usage Arguments Value Examples
Cumulative sum across groups
1 | cumSumGroup(x, group)
|
x |
vector of numeric values. |
group |
vector of grouping variable. |
A numeric vector.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | ### Some example data ###
group <- factor(rep(c("A", "B", "C"), each = 10))
position <- c(1:10, 1:10, 51:60)
values <- rep(1, 30)
### Plot with original positions ###
# Groups "A" and "B" overlap
plot(position, values, col = group)
### Plot with cumsum ###
# Notice how the points strech in distance
# That's because we keep calculating the
# cumulative sum within groups
plot(cumsum(position), values, col = group)
### Plot with cumSumGroup ###
# Now, on the x-axis, the points are separated
# by 1 unit WITHIN groups. But cumulatively
# ACROSS groups
plot(cumSumGroup(position, group), values, col = group)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.