Skip to content
Prev 300912 / 398503 Next

help with Loop

Hello,

Try the following.


d <- read.table(text="
D Y C
a 2005 10
a 2006 0
a 2007 9
b 2005 1
b 2006 0
b 2007 1
c 2005 5
c 2006 NA
c 2007 4 ", header=TRUE)
d

prn <- lapply(split(d, d$D), function(x){
     x <- x[!is.na(x$C), ]
     x[c(FALSE, diff(x$C)/x$C[-length(x$C)] < -0.5 & diff(x$C) < -5), ]
})
do.call(rbind, prn)

Hope this helps,

Rui Barradas

Em 23-07-2012 11:08, Katrin Ronnenberg escreveu: