Re: [R] Replace a for loop with a function

2011-09-19 Thread Jean V Adams
Eekhout, I. wrote on 09/19/2011 10:16:17 AM: > > Hi all, > > I would like to replace the for loop in the code below with a function > to improve the speed and to make the script more efficient. > The loop creates a vector of integers (x) with the probability of f for > each integer. > The lengt

Re: [R] Replace a for loop with a function

2011-09-19 Thread Eik Vettorazzi
sorry, there is a superfluous bracket at the end of the line, it should be read as sample(1:3,50,prob=c(0.5,0.15,0.35),replace=T) Am 19.09.2011 19:08, schrieb Eik Vettorazzi: > Hi Iris, > maybe I misinterpret this, but I think in the end it all comes down to > sample(1:3,50,prob=c(0.5,0.15,0.35),r

Re: [R] Replace a for loop with a function

2011-09-19 Thread Eik Vettorazzi
Hi Iris, maybe I misinterpret this, but I think in the end it all comes down to sample(1:3,50,prob=c(0.5,0.15,0.35),replace=T)) cheers Am 19.09.2011 17:16, schrieb Eekhout, I.: > Hi all, > > I would like to replace the for loop in the code below with a function > to improve the speed and to mak

[R] Replace a for loop with a function

2011-09-19 Thread Eekhout, I.
Hi all, I would like to replace the for loop in the code below with a function to improve the speed and to make the script more efficient. The loop creates a vector of integers (x) with the probability of f for each integer. The length of f is variable, but sums to 1. I tried to use a function