[R] Time outside limits

Bart Joosen bartjoosen at hotmail.com
Thu Oct 16 20:12:53 CEST 2014


Hi,
I'm currently facing the problem that I need to write a function where I get a dataframe back which contains the time (in hours) outside the limits of a temperature sensor, each month, and for how long exactly.
I wrote a for loop which check:- if a datapoint is outside the limit- if the previous datapoint is outside the limt, then count + 1- if the next datapoint isn't outside: write in dataframe.
I guess this could be with some vectorisation function, I tried with seq_along, and match, but couldn't figure it out.
Here some sample data:
y <- c(rnorm(10,25), rnorm(10,32),rnorm(10,25), rnorm(10,20), rnorm(10,25))x <- seq(c(ISOdate(2000,3,20)), by = "hour", length.out = length(y))
limits of y: c(22,27)
Thanks
Bart 		 	   		  
	[[alternative HTML version deleted]]



More information about the R-help mailing list