Hi Alex,
Michael is correct that vectorizing this is the way to go. Since this
is for class and vectorizing requires a bit of thought, I am not going
to demonstrate it with your function; however, here are some very
minor changes you can make that give fairly substantial performance
increases. I
Also, vectorize this puppy - that's how you really get the best performance out
of R, but in this case it will easily get rid of your problem.
Michael
On Nov 19, 2011, at 11:31 PM, Peter Langfelder
wrote:
> Well, you assign numeric(0) or numeric(0)+1, which is still
> numeric(0). No wonder t
Well, you assign numeric(0) or numeric(0)+1, which is still
numeric(0). No wonder the return value is always numeric(0).
You probably need to replace numeric(0) simply by 0. Numeric(0) does
not mean 0, it means a numeric vector of length zero (i.e., empty).
HTH,
Peter
On Sat, Nov 19, 2011 at 6:
Though it seems a pity to even hint, what value have you assigned to "phat"
and what is the value returned when the function runs?
On Saturday, November 19, 2011 18:52:20 alex_janssen wrote:
> Hi,
>
> I am trying to code buffons needle in R for a class
>
> This is my code w/ output from R, if a
Hi,
I am trying to code buffons needle in R for a class
This is my code w/ output from R, if anyone could tell me why this is
happening it would be amazing,
I can generate correct results without putting the steps into a function but
alas that is the assignment.
> buffon = function(n){
+ x = NUL
5 matches
Mail list logo