cumSumGroup: Cumulative sum across groups

Description Usage Arguments Value Examples

Description

Cumulative sum across groups

Usage

1

Arguments

x

vector of numeric values.

group

vector of grouping variable.

Value

A numeric vector.

Examples

 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)

tavareshugo/windowscanr documentation built on May 31, 2019, 3:57 a.m.