Skip to content

Paste in a FOR loop

5 messages · Michael Pearmain, Carlos J. Gil Bellosta, Dieter Menne +2 more

#
Michael Pearmain <mpearmain <at> google.com> writes:
..
Check documentation on HTMLInsertGraph, and don't forget to change the filename
in the loop, otherwise you always see the last file.

Dieter
#
On Wed, Dec 31, 2008 at 6:12 AM, Michael Pearmain <mpearmain at google.com> wrote:
...
This just constructs strings.  You actually want to call "summary" on
the value of the variable z.out.1 etc., so constructing the string
"z.out.1" or "summary(z.out.1" [sic] doesn't help.  To call summary on
the value of the variables, you can use:

     summary( get(paste("z.out",group,sep="")) ) ...

But in general, if you're not doing real meta-programming, the
presence of a "get" or even worse an "eval" in your code generally
indicates that you're not organizing your data appropriately.  Why not
have z.out be a *list* of values, so you can just write

    for (group in 1:3) { summary(z.out[[group]]); ...}

Hope this helps,

          -s