[R] Help with vector gymnastics
Eik Vettorazzi
E.Vettorazzi at uke.uni-hamburg.de
Thu Aug 23 14:17:54 CEST 2007
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 function will be
> answer = 5 5 5 5 25 30 30
>
> Thank you.
>
> Phil,
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
--
Eik Vettorazzi
Institut für Medizinische Biometrie und Epidemiologie
Universitätsklinikum Hamburg-Eppendorf
Martinistr. 52
22046 Hamburg
T ++49/40/42803-8243
F ++49/40/42803-7790
More information about the R-help
mailing list