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
> 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
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
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
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
5 matches
Mail list logo