Re: [R] Running something without a loop when the result from the previous iteration is require for the current iteration

2010-08-13 Thread Petr PIKAL
Hi wootten.adrie...@gmail.com napsal dne 12.08.2010 14:15:30: Not quite what I was trying to say. The process generates a random uniform number between 0 and 1 and compares to a specific conditional probability. It is looking for this in particular: random number Pr(

Re: [R] Running something without a loop when the result from the previous iteration is require for the current iteration

2010-08-13 Thread Adrienne Wootten
I did take your advice and change a few things in it to help it run. After reading through your earlier reply again I understood exactly what you were saying, so I did apply it in my function too. Thanks for all the advice! I appreciate it! Adrienne On Fri, Aug 13, 2010 at 3:29 AM, Petr PIKAL

Re: [R] Running something without a loop when the result from the previous iteration is require for the current iteration

2010-08-12 Thread Adrienne Wootten
Not quite what I was trying to say. The process generates a random uniform number between 0 and 1 and compares to a specific conditional probability. It is looking for this in particular: random number Pr( rain(station=i,day=d)=1 | rain(station=i,day=d-1)=0 rain(station=j,day=d)=0

Re: [R] Running something without a loop when the result from the previous iteration is require for the current iteration

2010-08-12 Thread Adrienne Wootten
Thanks everyone for your help and advice. For the R-help archives, here is what I ended up doing. First creating a separate function to handle one day at a time - byrow.gen2 - function(genmat,rownum,use1,use2,num,ortho_obs_used){ prev = rownum-1 ran = runif(length(rownum),0,1)

[R] Running something without a loop when the result from the previous iteration is require for the current iteration

2010-08-11 Thread Adrienne Wootten
Hello Everyone! Here's what I'm trying to do. I'm working on generating occurrences of precipitation based upon precipitation occurrence for a station during the previous day and two stations that have already been generated by joint probablities and 1st order Markov chains or by the same

Re: [R] Running something without a loop when the result from the previous iteration is require for the current iteration

2010-08-11 Thread Wu Gong
Hi Adrienne, I guess apply should be better than for loop. Code like this: event.gen2 = function(genmat,use1,use2,num,ortho_obs_used){ onerow.gen - function(one.row, use1){ one.row[num] - ifelse(...} genmat[,num] - NA ##Add one row with NA values

Re: [R] Running something without a loop when the result from the previous iteration is require for the current iteration

2010-08-11 Thread Greg Snow
What is wrong with using a loop? It used to be that loops were much slower than some of the alternatives, but now days a well crafted loop runs almost as fast (sometime faster) than the apply functions. So if the loop is working for you, use it and don't worry about it (though there may be

Re: [R] Running something without a loop when the result from the previous iteration is require for the current iteration

2010-08-11 Thread Adrienne Wootten
If it were just one loop by itself and I was doing the calculation for just one month for all of my 317 stations, I would agree with. However, this function itself is inside another loop which goes through each month and year that I need the calculation for each of the stations. If you have any