R中的EXP属性在R中不起作用
我想使用 R 中的复制函数复制一个表达式。该表达式是包含 lnnorm 分布的乘法。该表达式在复制函数之外给出了不同的结果,但是当我将其作为属性插入到复制函数中时,它只复制一个结果。例如,它多次给我相同的结果。
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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论