[R] efficient way to reduce running time
Dennis Murphy
djmuser at gmail.com
Tue Aug 2 15:56:58 CEST 2011
Hi:
Could you please provide a reproducible example? In your code,
(i) n is undefined;
(ii) logbp is undefined.
A description of what you want to do and/or a reproducible example
with an expected outcome would be useful.
As the bottom of each e-mail to R-help says...
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Dennis
On Tue, Aug 2, 2011 at 4:05 AM, Kathie <kathryn.lord2000 at gmail.com> wrote:
> Dear R users,
>
> Would you plz tell me how to avoid this "for" loop blow??
>
> I think there might be a better way to reduce running time.
>
> ----------------------------------------------------------------------------------------------
> ## y1 and y2 are n*1 vectors
>
> for (k in 1:n){
> ymax <- max( y1[k], y2[k] )
>
> i <- 0:ymax
>
> sums<- -lgamma(y1[k]-i+1)-lgamma(i+1)-lgamma(y2[k]-i+1)
>
> maxsums <- max(sums)
>
> sums <- sums - maxsums
>
> lsum <- log( sum(exp(sums)) ) + maxsums
>
> logbp[k] <- y1[k] + y2[k] + lsum
> }
>
> ------------------------------------------------------------------------------------
>
> Any suggestion will be greatly appreciated.
>
> Regards,
>
> Kathryn Lord
>
> --
> View this message in context: http://r.789695.n4.nabble.com/efficient-way-to-reduce-running-time-tp3711985p3711985.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
More information about the R-help
mailing list