[英]I'm trying to use the p.adjust function and I get the error object cannot be coerced to type 'double'
[英]I'm trying to create a function with expression() inside, but I get an error
我想創建這個 function
library(sde)
myfunction <- function(r,a,K,vi){
set.seed(123)
d <- expression(r*x*(K-x))
s <- expression(a*x*(K-x))
sde.sim(X0=1,drift=d, sigma=s,M=3) -> X
plot(X, main="Multiple")
}
但是當我運行 function 時:
myfunction(r=0.5,a=0.35,K=100,vi=1)
我得到
Error in eval(drift) : object 'r' not found
為什么R找不到expression()里面的對象?
我在 function 之外得到了想要的結果並分配了值; 但我想要一個 function 來做到這一點。 問題是 R 在 function 的 expression() 中找不到值。
r <- 0.5
a <- 0.35
K <- 20
vi <- 1
set.seed(123)
d <- expression(r*x*(K-x))
s <- expression(ax(K-x))
sde.sim(X0=1,drift=d, sigma=s,M=3) -> X
plot(X, main="Multiple")`
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.