Question

I wrote codes to simulate Weibull values based on 8 different shape parameters using for loop. I want to save it in matrix of 365 x 8 and eventually export to csv.

My code is this:

k <- seq(1.4,2.8,0.2)
test <- matrix(rep(NA,365),nrow=365,ncol=8)
for (i in k){
  wind.k <- mapply(rweibull,i,scale.k,MoreArgs=list(n=1))
  test[ ]<-as.matrix(wind.k)
}

The result is in 365 x8 but I notice that it only captures k=2 for every column. Could anyone help fix the codes?

Thank you very much for your help in advance!

Was it helpful?

Solution

Use this:

test <- matrix(rweibull(n=365*8, shape=k, scale=scale.k), nrow=365, ncol=8, byrow=TRUE)

Note that scale.k must be a length 8 vector.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top