[R] Time outside limits
Clint Bowman
clint at ecy.wa.gov
Thu Oct 16 22:36:00 CEST 2014
?rle
Clint Bowman INTERNET: clint at ecy.wa.gov
Air Quality Modeler INTERNET: clint at math.utah.edu
Department of Ecology VOICE: (360) 407-6815
PO Box 47600 FAX: (360) 407-7534
Olympia, WA 98504-7600
USPS: PO Box 47600, Olympia, WA 98504-7600
Parcels: 300 Desmond Drive, Lacey, WA 98503-1274
On Thu, 16 Oct 2014, daniel wrote:
> 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 <bartjoosen at 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 at 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 at 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.
>
More information about the R-help
mailing list