Re: [R] Loop: noob question

2011-08-05 Thread David Winsemius
On Aug 5, 2011, at 1:50 PM, Ken H wrote: That's a good point Josh is correct, Its the R Bible because its the size of the Bible and serves as a very good reference. Some people apparently think so [assuming here that you are referring to Crawley.] My experience is less favorable. When I

Re: [R] Loop: noob question

2011-08-05 Thread William Dunlap
) is a good tool in base R and the rbenchmark package makes it easy to compare various approaches. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > Behalf Of Bert Gunter >

Re: [R] Loop: noob question

2011-08-05 Thread Bert Gunter
I think that Josh may have inadvertently left out Venables's and Ripley"s MASS (the book), which is what I would choose if I were marooned on a desert island with my computer, a power supply, and unlimited mai tai's. Also Mozart's Piano Concerti if I had to limit my music to just one composer ( :-)

Re: [R] Loop: noob question

2011-08-05 Thread Ken H
That's a good point Josh is correct, Its the R Bible because its the size of the Bible and serves as a very good reference. I agree that it is definitely not a first blush kind of book. I second the regression book, it is excellent. Cryer and Chan Time Series Analysis with Applications in R is pret

Re: [R] Loop: noob question

2011-08-05 Thread Bert Gunter
Inline below. On Fri, Aug 5, 2011 at 10:23 AM, R. Michael Weylandt wrote: > Bert, > > You are absolutely correct: I was wrong not to vectorize in this case. > No. That wasn't my point at all. In this case, vectorizing doesn't seem to help because you still must do a loop (via *ply) in R. My poin

Re: [R] Loop: noob question

2011-08-05 Thread R. Michael Weylandt
Bert, You are absolutely correct: I was wrong not to vectorize in this case. I am surprised, however, by your remark that sapply() (or really lapply()) is faster than apply() -- is there a reason for this? I would have guessed that the major difference between the two would have been memory manag

Re: [R] Loop: noob question

2011-08-05 Thread Joshua Wiley
On Fri, Aug 5, 2011 at 9:20 AM, Ken H wrote: [snip] >   And that should be it, as far as relevant reading > Peter Daalgard's Introductory Statistics with R is very good if you do not > know other programming languages. I would strongly second this. It is a very nice book. What book to read depe

Re: [R] Loop: noob question

2011-08-05 Thread Bert Gunter
Michael: I'm sorry, but this "advice" is wrong. replicate() **IS** essentially a loop: it uses sapply(), which is basically an interpreted loop (with suitable caveats that R experts can provide). The correct advice is: whenever possible, move the loops down to underlying C code by vectorizing. In

Re: [R] Loop: noob question

2011-08-05 Thread Ken H
Hey, no problem! We all have to start somewhere, welcome to R! The structure of the for loop is as follows: First lets define the number you want, say >vector.size = 10 First allocate an empty vector to store the results, you could do this like so > V95.Vector<-c() But I recommend you do

Re: [R] Loop: noob question

2011-08-05 Thread R. Michael Weylandt
This is a textbook of when NOT to use a loop in R: rather make a function that does what you want and use the replicate function to do it repeatedly. f <- function(){ return(-1000*quantile(rnorm(250,0,0.2),0.95) } x = replicate(1e5,f()) There are your desired numbers. Some general coding princi

[R] Loop: noob question

2011-08-05 Thread UnitRoot
Hi, Can someone help me out to create a (for?) loop for the following procedure: x=rnorm(250,0,0.02) library(timeSeries) x=timeSeries(x) P=1000