remove!

Syntax

remove!(obj, index)

Details

Removes elements at specified positions from a vector or tuple, modifying the original object in place.

Compared to functions like drop, pop!, removeHead!, and removeTail!, remove! is more flexible as it allows deleting elements at any position, while the other functions only support removing elements from the head or tail.

Parameters

obj is a vector/array vector/tuple/columnar tuple indicating the target object from which element(s) will be removed.

index is an INT scalar/vector, indicating the zero-based position(s) of element(s) to remove. All indices must be within the range [0, obj.size()). If a vector is specified, indices must be strictly ascending.

Returns

Returns the updated vector or tuple after removal, with the same type and form as obj.

Examples

Remove specified elements from a regular vector.

v = 1..10
remove!(v, 2)  // v becomes [1,2,4,5,6,7,8,9,10]

// Continue from the previous result
remove!(v, [1,3,5])   // v becomes [1,4,6,8,9,10]

Remove specified elements from an array vector.

av = array(DOUBLE[], 0, 10).append!([[1.1,2.2], [3.3,4.4,5.5], [6.6], [7.7,8.8,9.9,10.0]])
remove!(av, 1)   // av becomes [[1.1,2.2], [6.6], [7.7,8.8,9.9,10.0]]

// Continue from the previous result
remove!(av, [0,2])   // av becomes [[6.6]]

Remove specified elements from a regular tuple.

tp = (1, `AAPL, 3.14, 2023.01.01)
remove!(tp, 2)  // tp becomes (1, `AAPL, 2023.01.01)

// Continue from the previous result
remove!(tp, [0,2]) // tp becomes (`AAPL)

Remove specified elements from a columnar tuple.

ctp = [[1,2,3], [4,5,6], [7,8], [9,2]].setColumnarTuple!()
remove!(ctp, 1)
// ctp becomes [[1,2,3], [7,8], [9,2]]

// Continue from the previous result, remove multiple elements
remove!(ctp, [0,1])
// ctp becomes [[9,2]]

Related functions:drop, pop!, removeHead!, and removeTail!