stretch

Syntax

stretch(X, n)

Arguments

X is a vector/tuple/matrix/table.

n is a non-negative integer.

Details

  • If X is a vector or tuple, stretches X evenly to a new vector or tuple with the length of n.

  • If X is a matrix or table, stretches X evenly to a new matrix or table with n rows.

The difference between stretch and take lies in:

  • take takes n values iteratively and sequentially from a vector, whereas stretch copies each element of the vector to stretch the vector to a new length n.

Examples

$ X = 1 NULL 2 3
$ print stretch(X, 11)
[1,1,1,,,,2,2,3,3]

$ print stretch(X, 11)
[1,1,1,,,,2,2,2,3,3]

$ print stretch(X, 12)
[1,1,1,,,,2,2,2,3,3,3]

$ print take(X, 10)
[1,,2,3,1,,2,3,1,]

$ s=[1 2 3, 4 5 6]
$ stretch(s, 5)
([1,2,3],[1,2,3],[1,2,3],[4,5,6],[4,5,6])

$ m=matrix(1 2 3, 4 5 6)
$ stretch(m,5)
col1        col2
1   4
1   4
2   5
2   5
3   6

$ t=table(1 2 3 as a, 4 5 6 as b)
$ stretch(t,5)
a   b
1   4
1   4
2   5
2   5
3   6