[R] Double FOR

Ales Ziberna aleszib at gmail.com
Sat Nov 26 17:34:22 CET 2005


Maybe you whould try:

One of your problems is that you are rewriting the resoults so that the 
resoult you get is only for the final combination of m, s, y.

Secondly, I am not sure if you want to use in the equation elements of m, s, 
y, or the whole vectors.

function (m,s,y)

{
DIC.hat<-NULL
for (j in m){

for (k in s){

for (i in y){



DIC.hat<-cbind(DIC.hat,c(m=j,s=k,y=i,DIC.hat=sum(-2*((log(1/sqrt(2*pi*k^2))*exp((((i-j)/k)^2)/-2)))))

}

}

}

DIC.hat

}


Best,
Ales Ziberna
----- Original Message ----- 
From: "Ginestet, Cedric" <c.ginestet at imperial.ac.uk>
To: <r-help at stat.math.ethz.ch>
Sent: Saturday, November 26, 2005 4:09 PM
Subject: [R] Double FOR


> Hi,
>
>
>
> I want to run through a formula several times with several different
> variables (which are defined by independent vectors of equal length 10
> elements). It looks like this:
>
>
>
>
>
> function (m,s,y)
>
> {
>
> for (j in m){
>
> for (k in s){
>
> for (i in y){
>
>
>
> DIC.hat<-sum(-2*((log(1/sqrt(2*pi*s^2))*exp((((y-m[j])/s)^2)/-2))))
>
> }
>
> }
>
> }
>
> DIC.hat
>
> }
>
>
>
>
>
> My problem is that R runs the three variables at the same time providing
> me with 10 new elements for DIC.hat, when I would like to have 20 times
> more.
>
>
>
> Can you help?
>
>
>
>
>
> ----------------------------------------------------
>
> Cedric Ginestet
>
> Department of Epidemiology and Public Health
>
> Faculty of Medicine
>
> Imperial College
>
> Norfolk Place
>
> London
>
> W2 1PG
>
> UK
>
> Tel:  +44 (0)77 8688 4313
>
> Fax: +44 (0)20 7402 2150
>
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html




More information about the R-help mailing list