search for: seriesidx

Displaying 1 result from an estimated 1 matches for "seriesidx".

2008 Jan 07
3
Seeking a more efficient way to find partition maxima
...= v[1:3], v2 = v[4], v3 = v[5:6]. I want to find the maximum element of each subvector. In this example, max(v1) is 4, max(v2) is 6, max(v3) is 7. If I knew that the successive subvector maxima would never decrease, as in the example, I could do the following: partiCmax <- function( values, seriesIdx ) { # assume seriesIdx is increasing integer sequence beginning with 1, ending at less than or equal to length(values) parti <- cbind( seriesIdx, c( ( seriesIdx[ -1 ] - 1 ), length( values ) ) ) return( cummax( values )[ parti[ , 2 ] ] ) } The use of cummax makes that pretty efficient,...