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
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
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 *
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,
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
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,
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
7 matches
Mail list logo