I am currently building a tool for university and need to run a loop over an if else statement and store the results in new variables. Would be great if you would have some advice for me.
The main idea of the tool is to simulate values of on data frame based on the user-input of another data frame. The user can decide between normal, triangle, etc. distribution.
What I need help with is the loop that changes on the one hand the new variable and on the other hand through the several columns of the first data frame.
This is my code so far:
runs = 10000
count.guv <- 3
count.distr <- 1
for (i in distribution){
if(distribution[i]==1){
sim.price.dev[i] <- rnorm(runs,mean = mean(data.matrix(df.guv.fiktiv[count.guv]), sd = sd(data.matrix(df.guv.fiktiv[count.guv]))))
} else if (distribution[i]==2){
sim.price.dev[i] <- rtriangle(runs,-0.05,0.05,mean(data.matrix(df.guv.fiktiv[count.guv])))
} else if (distribution[i]==3){
sim.price.dev[i] <- runif(runs,min=-0.05,max=0.05)
} else if (distribution[i]==4){
sim.price.dev[i] <- rlnorm(runs,meanlog = mean(log(data.matrix(df.guv.fiktiv[count.guv]))), sdlog = sd(log(data.matrix(df.guv.fiktiv[count.guv]))))
} else if (distribution[i]==5){
sim.price.dev[i] <- df.guv.fiktiv[nrow(df.guv.fiktiv),count.guv]
} else {
sim.price.dev&i <- df.guv.fiktiv[nrow(df.guv.fiktiv),count.guv]
}
count.guv <- count.guv+1
}