mergeSortedLists: Merge sorted numeric lists of almost increasing values.

mergeSortedListsR Documentation

Merge sorted numeric lists of almost increasing values.

Description

Given a list of numeric vectors, in each of which there come almost increasing sequences (that can be interrupted by decreasing values), mergeSortedLists merges them such that i) the relative order of any two values from an individual vector is preserved in the result, and ii) the resulting vector is sorted in increasing order, if this would not invalidate the first condition. In case of ties, the value from former vector takes precedence. For example: the list list(c(1,3,5,3), c(2,4,1,2)) gives the result of c(1,2,3,4,1,2,5,3).

Usage

mergeSortedLists(x, dbg = 0)

Arguments

x

a list of numeric vectors

dbg

debug level

Value

A list of two numeric vectors: x, the resulting vector of merged values, and idx, the indices of the selected values.

Author(s)

Tomas Sieger

Examples

mergeSortedLists(list(c(1,3,5,3), c(2,4,1,2)),dbg=1)
mergeSortedLists(list(1:10))
mergeSortedLists(list(1:2,1:2))
mergeSortedLists(list(c(),1,c()))

tsieger/tsiMisc documentation built on Oct. 10, 2023, 10:24 p.m.