Re: [R] Help writing basic loop

2011-09-20 Thread David L Carlson
43-4352 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of MacQueen, Don Sent: Friday, September 16, 2011 6:58 PM To: Luke Miller; beaulieu.j...@epamail.epa.gov Cc: r-help@r-project.org Subject: Re: [R] Help writing basic loop Just

Re: [R] Help writing basic loop

2011-09-16 Thread MacQueen, Don
Just a minor aside; I would have done my.slopes <- numeric(100) Note that: > class(numeric(5)) [1] "numeric" -Don -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 9/16/11 12:37 PM, "Luke Miller" wrote: >Create an output

Re: [R] Help writing basic loop

2011-09-16 Thread R. Michael Weylandt
You can also do the regressions "in parallel" as follows: x = -25:25 y = 0.05*x^2 + 2* x - 4 y1 = y + rcauchy(51) y2 = y + rcauchy(51)^2 y3 = y/10 - 5 + rnorm(51) Y = cbind(y, y1, y2, y3) m = lm(Y~x) print(coef(m)) Hope this helps, Michael On Fri, Sep 16, 2011 at 3:37 PM, Luke Miller wrote:

Re: [R] Help writing basic loop

2011-09-16 Thread Luke Miller
Create an output vector to hold your slopes before starting the loop, then use your index i to place each new slope in the appropriate position in your vector. y1<-rnorm(100, mean=0.01, sd=0.001) y2<-rnorm(100, mean=0.1, sd=0.01) x<-(c(10,400)) my.slopes = vector("numeric",100) # initialize a

[R] Help writing basic loop

2011-09-16 Thread Beaulieu . Jake
Hello, I would like to write a loop to 1) run 100 linear regressions, and 2) compile the slopes of all regression into one vector. Sample input data are: y1<-rnorm(100, mean=0.01, sd=0.001) y2<-rnorm(100, mean=0.1, sd=0.01) x<-(c(10,400)) #I have gotten this far with the loop for (i in 1:10