Skip to content
Prev 198903 / 398502 Next

avoiding loop

The first thing I would suggest is convert your dataframes to matrices
so that you are not having to continually convert them in the calls to
the functions.  Also I am not sure what the code:

	realized_prob = with(DF, {
     					ind <- (CHOSEN == 1)
     					n <- tapply(theta_multiple[ind], CS[ind], sum)
     					d <- tapply(theta_multiple, CS, sum)
     					n / d	
						})

is doing.  It looks like 'n' and 'd' might have different lengths
since they are being created by two different (CS & CS[ind])
sequences.  I have no idea why you are converting to the "DF"
dataframe.  THere is no need for that.  You could just leave the
vectors (e.g., theta_multiple, CS and ind) as they are and work with
them.  This is probably where most of your time is being spent.  So if
you start with matrices and leave the dataframes out of the main loop
you will probably see an increase in performance.

2009/11/2 parkbomee <bbom419 at hotmail.com>: