Skip to content
Prev 250269 / 398498 Next

How can we make a vector call a function element-wise efficiently?

Hello
	I have a time-comsuming program which need to simplify, I have tested the annotated program as follow:
+ { 
+   i <- seq(from=0, length=c) 
+   logx <- lchoose(NT-n, CT-i) + lchoose(n, i) 
+   logmax <- max(logx) 
+   logmax + log(sum(exp(logx - logmax))) 
+ }
[1] 2331  524  918  218 1100  547  289 1167  450 1723
[1] 10000
user  system elapsed 
  26.45    0.03   26.70
user  system elapsed 
  27.74    0.14   28.94 

I have about  300,000 such 26.70/ 28.94 seconds, so the approximate computation time is 100 days
What a terrible thing to do!!!
Any modification, nomatter how subtle, will be a big help for me

Thank you in advance

Yours sincerely
 



ZhaoXing
Department of Health Statistics
West China School of Public Health
Sichuan University
No.17 Section 3, South Renmin Road
Chengdu, Sichuan 610041
P.R.China

__________________________________________________
?????????????????????????????