简体   繁体   English

R中的建模单位消失时间

[英]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. 我正在尝试在R中建立一个发电单元的模型,该单元查看数据帧(可用(1/0))中的一列以开始(1),一旦参考值变为零,它就停止(0)。 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. 但是一旦停止,就会有一个最小的关闭间隔,因此即使可用值为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 示例:available(参考列)[1100111]单元(将要建模)[1100011]单元不能最早在第6步启动,因为最少停机时间为3小时

Help is highly appreciated. 非常感谢您的帮助。

here is an excel sample file showing what i want to achieve. 这是一个excel示例文件,显示了我想要实现的目标。 http://www.filedropper.com/sample_5 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: 1)regexpr如果问题是在两个连续的0之后立即找到第一个1,如果没有则返回0,则:

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. 2)rollapplyr另一种可能性是将字符串拆分为一个字符串,然后使用rollappyr查找采用第一个的c("0", "0", "1")序列。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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