考虑以下代码(Matlab)
function counter = ross_fpt_uniform
%ROSS_FPT_UNIFORM generates the first passage time of the sum of uniform
% random variables exceeding level 1.
s = 0;
counter = 0;
while (s <= 1)
s = s + rand(1,1);
counter = counter + 1;
end
end %ross_fpt_uniform
我无法将function counter = ross_fpt_uniform
转换为R
这让我感到困惑,我该如何对待counter
,因为在这里counter = counter + 1;
似乎是一个变量。它是函数还是变量,如何用R编写?
我当前的r代码如下:
counter<-function() {
s<-0
counter<-0
while(s<=1){
s <- s + runif(1)
counter <- counter+1
}
}