R 使用元函数迭代多个值

R 使用元函数迭代多个值,r,function,R,Function,我试图用元函数来模拟这个算术表达式: 本质上,我想要来自-1的随机实数,你可以像这样做 am_thirteen <- function(x, y, theta) { x1 <- runif(x, 0, 1) y2 <- runif(y, 0, 20) theta3 <- runif(theta, 0, 1) -(1 / theta3) * log10(1 + (((exp(-theta3 * x1) - 1) * (exp(-theta3 * y2) -

我试图用元函数来模拟这个算术表达式:

本质上,我想要来自
-1的随机实数,你可以像这样做

am_thirteen <- function(x, y, theta) {
  x1 <- runif(x, 0, 1)
  y2 <- runif(y, 0, 20)
  theta3 <- runif(theta, 0, 1)
  -(1 / theta3) * log10(1 + (((exp(-theta3 * x1) - 1) * (exp(-theta3 * y2) - 1)) / (exp(-theta3) - 1)))
}

“我想从-1Ah开始随机整数值是的,我是指实数。谢谢你注意这一点。但是,如果你想要实数,为什么要使用
舍入
?无论如何,如果你想在随机选择的点的网格上应用你的函数,请查看
展开。网格
我必须再次检查整数和实数的含义。”n、 舍入是不必要的,我实际上模仿了以前代码中的那个部分,因为当时我对它有不同的意图。似乎我没有用我的代码合理化,也没有用我想要的东西合理化。你可以忽略
Round
,并瞄准
-1@JohnColeman
expand.grid
对我来说是新的,尽管它看起来非常简单刷新。但是,在使用
expand.grid(am_十三(4,4,4))
时,我得到了4列和多次重复,这是我的函数的问题吗?
lapply(c(10, 10, 10), am_thirteen)
am_thirteen <-function(x, y, theta){
     (-(1/theta)*log10(1+(((exp(-theta*x)-1)*(exp(-theta*y)-1))/(exp(-theta)-1))))
 }

am_thirteen(runif(30, -1, 1),runif(30, -1, 1) ,runif(30, -1, 1) )
 [1] -0.1171828665 -0.1084171900 -0.2441978216  0.0256141946  0.0131042671  0.0844813069 -0.2898303502 -0.0051398158  0.0211143988  0.0667284968  0.0956009788 -0.2560234695
[13]  0.0039000563  0.0438593991 -0.0405444828 -0.1644587072 -0.0740161357  0.0652280253  0.0009757007  0.1854526942 -0.0905563222  0.0223378333 -0.0274033047 -0.2896201555
[25] -0.0173795526 -0.1840047563           NaN -0.1889213392 -0.0772152240 -0.0233664868
am_thirteen <- function(x, y, theta) {
  x1 <- runif(x, 0, 1)
  y2 <- runif(y, 0, 20)
  theta3 <- runif(theta, 0, 1)
  -(1 / theta3) * log10(1 + (((exp(-theta3 * x1) - 1) * (exp(-theta3 * y2) - 1)) / (exp(-theta3) - 1)))
}
> am_thirteen(30, 30, 30)
 [1] 0.24717749 1.05846557 0.45755718 0.66018800 0.03834795 0.39526527
 [7] 1.99589251 3.43298477 0.56534793 1.01813706 0.49402778 0.53281734
[13] 1.15933195 2.30322906 0.12077730 0.06233150 0.05681387 0.32175138
[19] 1.39598926 0.63679915 0.77333056 0.03321481 0.31202521 0.83615194
[25] 0.64084402 0.69740361 0.61896551 2.28605706 0.92365230 0.21639357