Re: [R] how to do away for loop using functionals?

2015-10-14 Thread Annie Hawk via R-help
Thank you Mike for looking into the problem and your helpful advice, really appreciate that.  Also, thank you Bill for pointing out the bad data.frame code.I modified the codes per your suggestions and run some time tests on n=2000 (increase # obs and groups as I actually have a much bigger data

Re: [R] how to do away for loop using functionals?

2015-10-14 Thread William Dunlap
> df=as.data.frame(cbind( sort(rnorm(mean=15,sd=10, n)),runif(n), rbinom(n, 1, 0.4) , g )) This is a lousy way to make a data.frame - the cbind forces all columns to be the same type and forces them into one vector then as.data.frame splits them up into separate columns again. You also get weird

Re: [R] how to do away for loop using functionals?

2015-10-14 Thread Michael Hannon
I've done a simple-minded transliteration of your code into code using nested lapply's. I doubt that it buys you much in terms of performance (or even clarity, which is really one of the main advantages of the `apply` family). > A [,1] [,2] [,3] [,4] [,5] [1,] 3.06097 6

Re: [R] how to do away for loop using functionals?

2015-10-13 Thread Michael Hannon
The answer to "another note" is: mapply(rep, w, 5:1) I'll try to look at the first part in more detail later today. -- Mike On Mon, Oct 12, 2015 at 5:55 PM, Annie Hawk via R-help wrote: > HI R-experts, > > > I am trying to speed up my calculation of the A results below and replace the > for

[R] how to do away for loop using functionals?

2015-10-12 Thread Annie Hawk via R-help
HI R-experts, I am trying to speed up my calculation of the A results below and replace the for loop withsome functionals like lapply.  After manyreadings, trial and error, I still have no success.  Would anyone please give me some hints onthat?  Thank you in advance. Anne  The program i