代表错误:invalide'times'参数 [英] Error in rep: invalide 'times' argument

查看:256
本文介绍了代表错误:invalide'times'参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试运行以下代码10000次迭代时,出现以下错误.rep(G1 [,2],G1 [,3])中的错误:无效的'times'参数.因此,不知道如何更改代码以修复该错误.基本上,只是想使用故障时间和一年中的维修时间等式来为发电机性能创建时间序列,这样我就可以得出发电机不在运行时的时间序列(以小时为单位).起始条件是发电机在第一个小时运行.可以肯定的是,有一个更好的模拟解决方案,我只是找不到它.任何意见或帮助将不胜感激.

When I try to run the following code for 10000 iterations I get the following error.Error in rep(G1[, 2], G1[, 3]) : invalid 'times' argument. So don't know how to change the code to fix that error. Basically just want to create time series for the generator performance using the equation for Time to fail and time to repair for 8736 hours in the year so that I have the time series in hours when the generator is operating in when is not. The starting conditions is that the generator is operating on the first hour. For sure there is a more elegant solution for simulating this I'm just not able to find it. Any comment or help will be appreciated.

MTTF<-2940 # MEDIUM TIME TO FAIL(hours)
MTTR<-60 # MEDIUM TIME TO REPAIR (hours)
TTF<--MTTF*log(runif(100))# equation for Time to fail 
TTR<--MTTR*log(runif(100))# equation for Time to repair
mix<-rep(0,length(TTF)+length(TTR))
sw<-rep(0,length(TTF)+length(TTR))
for(i in 1:length(TTF)){
mix[2*i-1]<-TTF[i]
sw[2*i-1]<-1
mix[2*i]<-TTR[i]
}
cmix<-cumsum(mix)
ccmix<-cbind(cmix[1:which(cmix>8736)],sw[1:which(cmix>8736)])
ccmix[dim(ccmix)[1],1]<-8736


G1<-round(ccmix)
# transform binary values
G1[G1 == 1] <- 12 # is the capacity of the generator

G1 <- cbind(G1, c(G1[1,1], diff(G1[,1])))
a1 <- rep(G1[,2], G1[,3]) ## GENERATING 8736 Values

因此,所需的输出为8736值,当ON时为12,而OFF时为0

So the desired output are 8736 values of 12 when is ON and 0 when is OFF

推荐答案

检查G1[,3]是什么.错误可能是由times参数中的负值

Check what G1[,3] is. Error can be caused by negative values in times argument

这篇关于代表错误:invalide'times'参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆