Hi,

 

I am trying to do the following computation:

 

      p <- rep(0, n)

      coef <- runif(K+1)

      U <- matrix(runif(n*(2*K+1)), n, 2*K+1)

      for (i in 0:K){

      for (j in 0:K){

      p <- p + coef[i+1]* coef[j+1] * U[,i+j+1]

      } }

 

I would appreciate any suggestions on how to perform this computation
efficiently without the "for" loops?

 

Thank you,

Ravi.

----------------------------------------------------------------------------
-------

Ravi Varadhan, Ph.D.

Assistant Professor, The Center on Aging and Health

Division of Geriatric Medicine and Gerontology 

Johns Hopkins University

Ph: (410) 502-2619

Fax: (410) 614-9625

Email: rvaradhan@jhmi.edu

Webpage:  http://www.jhsph.edu/agingandhealth/People/Faculty/Varadhan.html

 

----------------------------------------------------------------------------
--------

 


	[[alternative HTML version deleted]]

