R中的EXP属性在R中不起作用

发布于 2025-01-19 07:36:31 字数 1076 浏览 1 评论 0原文

我想使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文