change_index: Indexing of Changes in Runs

Description Usage Arguments Value See Also Examples

Description

Find the indices of changes in runs in a vector. This function pairs well with split_index and is the default for the indices in all split_index functions that act on atomic vectors.

Usage

1

Arguments

x

A vector.

...

ignored.

Value

Returns a vector of integer indices of where a vector initially changes.

See Also

split_index

Examples

1
2
3
4
5
6
7
8
set.seed(10)
(x <- sample(0:1, 20, TRUE))
change_index(x)
split_index(x, change_index(x))


(p_chng <- change_index(CO2[["Plant"]]))
split_index(CO2[["Plant"]], p_chng)

Example output

 [1] 1 0 0 1 0 0 0 0 1 0 1 1 0 1 0 0 0 0 0 1
 [1]  2  4  5  9 10 11 13 14 15 20
[[1]]
[1] 1

[[2]]
[1] 0 0

[[3]]
[1] 1

[[4]]
[1] 0 0 0 0

[[5]]
[1] 1

[[6]]
[1] 0

[[7]]
[1] 1 1

[[8]]
[1] 0

[[9]]
[1] 1

[[10]]
[1] 0 0 0 0 0

[[11]]
[1] 1

 [1]  8 15 22 29 36 43 50 57 64 71 78
[[1]]
[1] Qn1 Qn1 Qn1 Qn1 Qn1 Qn1 Qn1
12 Levels: Qn1 < Qn2 < Qn3 < Qc1 < Qc3 < Qc2 < Mn3 < Mn2 < Mn1 < ... < Mc1

[[2]]
[1] Qn2 Qn2 Qn2 Qn2 Qn2 Qn2 Qn2
12 Levels: Qn1 < Qn2 < Qn3 < Qc1 < Qc3 < Qc2 < Mn3 < Mn2 < Mn1 < ... < Mc1

[[3]]
[1] Qn3 Qn3 Qn3 Qn3 Qn3 Qn3 Qn3
12 Levels: Qn1 < Qn2 < Qn3 < Qc1 < Qc3 < Qc2 < Mn3 < Mn2 < Mn1 < ... < Mc1

[[4]]
[1] Qc1 Qc1 Qc1 Qc1 Qc1 Qc1 Qc1
12 Levels: Qn1 < Qn2 < Qn3 < Qc1 < Qc3 < Qc2 < Mn3 < Mn2 < Mn1 < ... < Mc1

[[5]]
[1] Qc2 Qc2 Qc2 Qc2 Qc2 Qc2 Qc2
12 Levels: Qn1 < Qn2 < Q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