Re: [R] Seeking a more efficient way to find partition maxima

2008-01-07 Thread jim holtman
Does this do what you want? > x <- c(1,4,2,6,7,5) > x.i <- c(1,4,5) > partiMax <- function(vec, index){ + # create a vector to identify the subvectors + x.b <- diff(c(index, length(vec) + 1)) + # split up the vector + x.s <- split(vec, rep(seq_along(index), times=x.b)) + unlist

Re: [R] Seeking a more efficient way to find partition maxima

2008-01-07 Thread Talbot Katz
home 917-656-5351cell t o p k a t z @ m s n . c o m > Date: Mon, 7 Jan 2008 13:49:13 -0500 > From: [EMAIL PROTECTED] > To: [EMAIL PROTECTED] > Subject: Re: [R] Seeking a more efficient way to find partition maxima > CC: [EMAIL PROTECTED] > > Try testing the performance

Re: [R] Seeking a more efficient way to find partition maxima

2008-01-07 Thread Gabor Grothendieck
Try testing the performance of transforming your series to one in which the values of each partition are larger than all prior partitions and the untransforming back: # test data myseq <- c(1, 4, 2, 6, 7, 5) part <- c(1, 4, 5) M <- max(myseq) # transform myseq2 <- myseq + M * cumsum(replace(0 *

Re: [R] Seeking a more efficient way to find partition maxima

2008-01-07 Thread Marc Schwartz
Talbot, Try this: PartMax <- function(x, breaks) { breaks <- c(breaks, length(x) + 1) sapply(seq(length(breaks) - 1), function(i) max(x[breaks[i]:(breaks[i + 1] - 1)], na.rm = TRUE)) } > PartMax(c(1,4,2,6,7,5),c(1,4,5)) [1] 4 6 7 > PartMax(6:1,c(1,4,

Re: [R] Seeking a more efficient way to find partition maxima

2008-01-07 Thread Talbot Katz
m > Date: Mon, 7 Jan 2008 10:44:20 -0600 > From: [EMAIL PROTECTED] > To: [EMAIL PROTECTED] > CC: [EMAIL PROTECTED] > Subject: Re: [R] Seeking a more efficient way to find partition maxima > > Talbot Katz wrote: >> Hi. >> >> Suppose I have a vector that I partiti

Re: [R] Seeking a more efficient way to find partition maxima

2008-01-07 Thread Marc Schwartz
Talbot Katz wrote: > Hi. > > Suppose I have a vector that I partition into disjoint, contiguous > subvectors. For example, let v = c(1,4,2,6,7,5), partition it into > three subvectors, v1 = v[1:3], v2 = v[4], v3 = v[5:6]. I want to > find the maximum element of each subvector. In this example,

[R] Seeking a more efficient way to find partition maxima

2008-01-07 Thread Talbot Katz
Hi. Suppose I have a vector that I partition into disjoint, contiguous subvectors. For example, let v = c(1,4,2,6,7,5), partition it into three subvectors, v1 = 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