Skip to content
Prev 227953 / 398500 Next

loop troubles

I tried that, this is what I tried, but I only get it to do one iteration
and then it wont cycle back. I am not sure how to tell it how to look at the
previous precision to add to the current new sample precision to get the new
precision. This is my first try at a loop so I am not sure if I am doing
anything right, sorry about the elementary question.

n=c(5,10,15)
ybar=c(12,13,14)
sd=c(2,3,4)
mutotals<-matrix(nrow=length(n), ncol=1)
mu=1;p0=0
for (i in 1:length(n)){
  var = sd[i]^2 #sample variance
  p = n[i]/var #sample precision
  p0[i]= i
  pn = p0[i]+p[i]
  mu.out = ((p0[i])/(pn)*mu[i])+((p)/(pn))*ybar[i]
  sigma[i] = 1/sqrt(pn[i])
  mutotals[i,]<-mu.out[i]
}

Joe King
206-913-2912
jp at joepking.com
"Never throughout history has a man who lived a life of ease left a name
worth remembering." --Theodore Roosevelt



-----Original Message-----
From: David Winsemius [mailto:dwinsemius at comcast.net] 
Sent: Sunday, July 18, 2010 5:36 AM
To: Joe P King
Cc: r-help at r-project.org
Subject: Re: [R] loop troubles
On Jul 17, 2010, at 9:09 PM, Joe P King wrote:

            
Perhaps if you set the problem up with vectors, it would become more  
obvious how to do it with indexing or loops:

n <-  c(5, 10, 15)
ybar <- c(12,12,14)  # and so on...