我写了一个函数如下
preg_match("/session=(\\w+)/", $var, $session);
echo $session[1]; // => "9efae87dd67"
这给了我这样的不良输出
simsim=function(n,model){
df=duplication
for(j in 2:(n+1)){
for(i in 3:(n_T-1)){
t_ip=df[i-2,j]
knownDensity=function(t_i){conDensity(t_i,t_ip,i,model)}
maxDensityValue <- optimise(knownDensity,lower=t_ip,upper=10,maximum=TRUE,tol=1e-10)[[2]]
df[i-1,j]=RejectionSampling(1)
}
}
return(df[,1:(n+1)])
}
但是如下所示,当我执行相同的代码内容而不是函数时,它运行良好!
numberOfLineages time1 time2
1 2 0.000000 0.000000
2 3 9.336734 9.234336
3 4 9.168868 9.631127
4 5 9.530523 9.496153
5 6 9.836319 9.110507
6 7 9.083733 9.770084
7 8 9.215956 9.688086
8 9 9.518183 9.100278
9 10 9.624247 9.323526
10 11 9.087299 9.890821
11 12 9.860937 9.177940
12 13 9.842235 9.307364
13 14 9.546416 9.190418
14 15 9.753121 9.499723
15 16 9.368431 9.107371
16 17 9.157236 9.112211
17 18 9.548059 9.199476
18 19 9.338566 9.185450
19 20 9.838453 9.403675
20 21 9.162214 9.324189
21 22 9.543628 9.081443
22 23 9.826989 9.676520
23 24 9.678934 9.754507
24 25 9.185565 9.461084
25 26 9.210276 9.240934
26 27 9.088698 9.596043
27 28 9.115626 9.316785
28 29 9.852018 9.503212
29 30 9.241426 9.130218
30 31 9.402581 9.356230
31 32 10.000000 10.000000
在未作为函数执行时完全按照我的要求输出。但我需要将它作为进一步编程的功能。有任何想法吗?提前致谢。 (正如您所看到的,使用了许多自定义函数,因此我无法将它们全部发布。)
n=2
model="subf"
df=duplication
for(j in 2:(n+1)){
for(i in 3:(n_T-1)){
t_ip=df[i-2,j]
knownDensity=function(t_i){conDensity(t_i,t_ip,i,model)}
maxDensityValue <- optimise(knownDensity,lower=t_ip,upper=10,maximum=TRUE,tol=1e-10)[[2]]
df[i-1,j]=RejectionSampling(1)
}
}
df[,1:(n+1)]