[R] While loop history

Jeff Newmiller jdnewmil at dcn.davis.CA.us
Mon Apr 8 01:23:18 CEST 2013


Vectors. Data frames are lists of vectors. Create longer vectors and perform computations vector-wise on all simulation data sets at once. Depending on the type of simulation, matrices and linear algebra may help as well.
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.

C W <tmrsg11 at gmail.com> wrote:

>May I say also ask one thing?  @OP: sorry to use your post.
>
>What would you use instead of loops?  I am aware of the apply()
>functions,
>but they are wrapper function of for loops, so they are slower.  At one
>point, I was told to go back to C for faster implementation, but I like
>R
>much more.
>
>In the case of repeated simulation such as Monte Carlo, what would you
>use
>instead of for loop?
>
>Mike
>On Sun, Apr 7, 2013 at 7:43 AM, John Kane <jrkrideau at inbox.com> wrote:
>
>>
>>
>http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example
>>
>> Loops are seldom a good solution in R so some more information and
>data
>> would be useful
>>
>> At the simplist, for your specific question  I think you could set up
>two
>> vectors (e.g. v1  <-  rep(NA, 10 ) and just write the values into the
>> vectors as you proceed through the loop.
>>
>> John Kane
>> Kingston ON Canada
>>
>>
>> > -----Original Message-----
>> > From: bayywater at gmail.com
>> > Sent: Sun, 7 Apr 2013 14:36:33 +1200
>> > To: r-help at r-project.org
>> > Subject: [R] While loop history
>> >
>> > Hi,
>> > I am new at R and still trying to get the hang of things.
>> > I am running a while loop and wish to save the results of each
>iteration.
>> > The results are a vector x of length two and I wish to save the
>results
>> > of
>> > each iteration as two vectors, one for x[1] and the other for x[2].
>> >
>> > Thanks!
>> >
>> >       [[alternative HTML version deleted]]
>> >
>> > ______________________________________________
>> > R-help at r-project.org mailing list
>> > https://stat.ethz.ch/mailman/listinfo/r-help
>> > PLEASE do read the posting guide
>> > http://www.R-project.org/posting-guide.html
>> > and provide commented, minimal, self-contained, reproducible code.
>>
>> ____________________________________________________________
>> GET FREE SMILEYS FOR YOUR IM & EMAIL - Learn more at
>> http://www.inbox.com/smileys
>> Works with AIM�, MSN� Messenger, Yahoo!� Messenger, ICQ�, Google
>Talk� and
>> most webmails
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>	[[alternative HTML version deleted]]
>
>
>
>------------------------------------------------------------------------
>
>______________________________________________
>R-help at r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list