[R] Creating data using multiple for loops

Bert Gunter bgunter@4567 @end|ng |rom gm@||@com
Tue Aug 20 00:01:01 CEST 2019


From section 9.2.2 (on looping) in "An Introduction to R":

"*Warning*: for() loops are used in R code much less often than in compiled
languages. Code that takes a ‘whole object’ view is likely to be both
clearer and faster in R."

Web searching on "for loops in R" and similar will give you further
comments and perspectives.

Cheers,
Bert


Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Mon, Aug 19, 2019 at 2:12 PM Jim Lemon <drjimlemon using gmail.com> wrote:

> Hi Greg,
> I replied because I thought the name of the "expand.grid" function can
> be puzzling. While "expand.grid" is a very elegant and useful
> function, it is much easier to see what is happening with explicit
> loops rather than loops buried deep inside "expand.grid". Also note
> Bill's comment about producing repeats by converting numeric values to
> character without the leading zeros. You can also use "formatC" to
> deal with that problem.
>
> Jim
>
> On Tue, Aug 20, 2019 at 12:05 AM <g.eastham.gilbert using gmail.com> wrote:
> >
> > Jim,
> >
> > Thank you very much for your help. I have "unpacked" the code and have a
> rudimentary understanding of what you did. Thanks again. However, I have no
> idea to what Bert is referring. Could you help me understand his
> suggestion? Thanks.
> >
> > -Greg
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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]]



More information about the R-help mailing list