exp attribute in replicate function in R is not working

171 views Asked by At

I want to replicate an expression using the replicate function in R. The expression is a multiplication containing lnorm distribution. The expression gives different results outside the replication function but when I insert it as an attribute into the replicate function it just replicates one result. It gives me e.g the same result many times.

d1 <- SumConcAcrylamide <- as.data.frame(SumConcAcrylamide)
d2 <- SumFoodIntakeBothDays <- as.data.frame(SumFoodIntakeBothDays)

library(data.table)

set.seed(123)

d3 <- setDT(d2)[(d1), Value_new :=
                  TotsumIntake_Perp*rnorm(n=1,d1$Loc, d2$Shape), on = "FoodCat"]
                    
#replicate this simulation 1000 times
                  
outcome <- replicate(n=2, {d3= setDT(d2)[(d1), Value_new :=
                                           TotsumIntake_Perp*rnorm(n=1,d1$Loc, d2$Shape), on = "FoodCat"]}, simplify = FALSE)
                                                                
### d3 if you run it many times you get a dataframe with different numbers for the Value_new column each time
                                                                
### When I run the outcome I get two times or as many times I set in the n=2,3.... attribute, the same numbers for the Value_new column
0

There are 0 answers