REPELEMENTS

Purpose:

Replicates individual elements of a series.

Syntax:

REPELEMENTS(series, idx, n)

 series - A series. idx - Optional. A series, a list of integer indices of the elements to replicate. Defaults to 1..length(n) n - A series. A list of integers specifying the number of times to replicate an element. 0 implies skip the element.

A series.

Example:

a = 1..10

b = repelements(a, {3, 2, 0, 1})

b == {1, 1, 1, 2, 2, 4}

REPELEMENTS implies:

Repeat the first element 3 times.

Repeat the second element 2 times.

Skip the third element.

Repeat the fourth element once and combine all sections.

Example:

a = 1..10

b = repelements(a, {1, 2, 4}, {3, 2, 1})

b == {1, 1, 1, 2, 2, 4}

REPELEMENTS implies:

Repeat the first element 3 times.

Repeat the second element 2 times.

Repeat the fourth element once and combine all sections.

Example:

W1: 1..5

W2: repelem(w1, 1..3)

W3: repelem(w1, 2..4, 1..3)

W4: repelem(w1, 3..5, 1..3)

W1 == {1, 2, 3, 4, 5}

W2 == {1, 2, 2, 3, 3, 3}

W3 == {2, 3, 3, 4, 4, 4}

W4 == {3, 4, 4, 5, 5, 5}

Example:

W1: 1..3

W2: repelem(w1, 3 * ones(3, 1))

W3: rep(w1, 3)

W1 == {1, 2, 3}

W2 == {1, 1, 1, 2, 2, 2, 3, 3, 3}

W3 == {1, 2, 3, 1, 2, 3, 1, 2, 3}

Remarks:

REPELEMENTS is similar to REPLICATE except individual elements are replicated.

A value of n < 0 implies skip the element.

If there are fewer idx indices than n values or fewer n values than idx indices,  the last idx or n value is used.

REPELEMENTS can be abbreviated REPELEM.

See REPLICATE to repeat a series n times.

RAVEL

REPCOLUMN

REPLICATE

REPMAT

SEREXTRACT