Bart, Check if the following could help you.
library(xts) 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)) z <- xts( y, order.by=as.POSIXct(x)) limit <- ifelse( lag(z) < 22 | z > 27, 1, 0) Daniel Merino 2014-10-16 15:12 GMT-03:00 Bart Joosen <bartjoo...@hotmail.com>: > 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]] > > ______________________________________________ > R-help@r-project.org 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. > -- Daniel [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org 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.