简体   繁体   中英

modeling unit donwn time in R

I am trying to model a power generation unit in R which looks at a column in data frame (available (1/0)) to start (1) and it stops (0) once the reference value becomes zero. But once it stops there is a minimum shut down interval, therefore it cant start right away even if the value of available is 1.

example: available(reference column)[1100111] unit (to be modelled) [1100011] unit cant start as early as 6th step as there is a minimum downtime of 3 hours

Help is highly appreciated.

here is an excel sample file showing what i want to achieve. http://www.filedropper.com/sample_5

1) regexpr If the problem is to find the first 1 immediately following two consecutive 0s and return 0 if none then:

x <- c("1100011", "010101") # test data

r <- regexpr("001", x)
ifelse(r > 0, r + 2, 0)
## [1]  6 0

2) rollapplyr Another possibility is to split the string into one character strings and then use rollappyr to find the c("0", "0", "1") subsequences taking the first.

library(zoo)

spl <- strsplit(x, "")
roll <- function(x) which.max(rollapplyr(x, 3, identical, c("0", "0", "1"), fill = FALSE))
out <- sapply(spl, roll)
out <- ifelse(out == 1, 0, out)
out
## [1]  6 0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM