Skip to content
Prev 300179 / 398521 Next

Imposing more than one condition to if

Hello,

There are obvious bugs in your code, you are testing for light > 2 or 
ligth < 2 but this would mean that dusk and dawn are undetermined for 
light == 2 and that they happen at light == 1.

Without loops or compound logical conditions:


f <- function(x){
	x$dawn <- x$time[ which.min(x$light) ]
	x$dusk <- x$time[ max(which(x$light == 0)) + 1 ]
	x
}

do.call(rbind, by(d, d$day, f))

Hope this helps,

Rui Barradas

Em 15-07-2012 17:32, Santiago Guallar escreveu: