When I try to run the following code for 10,000 iterations, I get the following error message .Error in rep (G1 [, 2], G1 [, 3]): invalid argument "times". Therefore, I do not know how to change the code to fix this error. Basically, I just want to create time series for generator performance, using the equation for Time to fail and the recovery time for 8736 hours a year, so that I have a time series in the generator hours when it is not. The initial conditions are that the generator runs in the first hour. Surely there is a more elegant solution to simulate this, I just can not find it. Any comments or help would be appreciated.
MTTF<-2940
MTTR<-60
TTF<--MTTF*log(runif(100))
TTR<--MTTR*log(runif(100))
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)
G1[G1 == 1] <- 12
G1 <- cbind(G1, c(G1[1,1], diff(G1[,1])))
a1 <- rep(G1[,2], G1[,3])
, 8736 12, , 0,