Re: [R] Basic question about re-writing for loop as a function

2011-08-31 Thread Jim Holtman
use Rprof to see where thr time is spent. take the strsplit out of the loop and do it once outsidr to create an object you can test against in the loop. you can probably get rid of the loop easily, but since there is no example of the data, it is hard to create a solution. Sent from my iPad

Re: [R] Basic question about re-writing for loop as a function

2011-08-31 Thread Jim Holtman
sorry, did not see your data at the bottom of the email Sent from my iPad On Aug 29, 2011, at 9:55, Chris Beeley chris.bee...@gmail.com wrote: Hello- Sorry to ask a basic question, but I've spent many hours on this now and seem to be missing something. I have a loop that looks like

[R] Basic question about re-writing for loop as a function

2011-08-29 Thread Chris Beeley
Hello- Sorry to ask a basic question, but I've spent many hours on this now and seem to be missing something. I have a loop that looks like this: mainmat=data.frame(matrix(data=0, ncol=92, nrow=length(predata$Words_MH))) for(i in 1:length(predata$Words_MH)){ for(j in 1:92){

Re: [R] Basic question about re-writing for loop as a function

2011-08-29 Thread Patrick Burns
You are somewhere in Circles 3 and 4 of 'The R Inferno'. If you have a function to apply over more than one argument, then 'mapply' will do that. But you don't need to do that -- you can do the operation you want efficiently: *) create your resulting matrix with all zeros, no reason for this