try
5*which(tf)[cumsum(tf)]
Gladwin, Philip schrieb:
Hello,
What is the best way of solving this problem?
answer - ifelse(tf=TRUE, i * 5, previous answer)
where as an initial condition
tf[1] - TRUE
For example if,
tf - c(T,F,F,F,T,T,F)
over i = 1 to 7
then the output of the
Hello,
What is the best way of solving this problem?
answer - ifelse(tf=TRUE, i * 5, previous answer)
where as an initial condition
tf[1] - TRUE
For example if,
tf - c(T,F,F,F,T,T,F)
over i = 1 to 7
then the output of the function will be
answer = 5 5 5 5 25 30 30
Thank you.
Phil,
library(zoo)
tf - c(T,F,F,F,T,T,F)
i - seq(7)
answer - ifelse(tf, i*5, NA)
answer - na.locf(answer)
On 8/23/07, Gladwin, Philip [EMAIL PROTECTED] wrote:
Hello,
What is the best way of solving this problem?
answer - ifelse(tf=TRUE, i * 5, previous answer)
where as an initial condition
Philip -
I don't know if this is the best way, but it gives you the output you
want.
Using your tf,
vals - rle(ifelse(tf, 5*which(tf), 0))
vals$values[vals$values == 0] - vals$values[which(vals$values==0) - 1]
inverse.rle(vals)
[1] 5 5 5 5 25 30 30
Gladwin, Philip wrote:
Hello,
What