[R] creating files using for loop

Brian Quinif bquinif at gmail.com
Fri Apr 7 07:40:45 CEST 2006


I tried that, and the problem seems to be that the results of the
'paste'ing are enclosed in quotes...that is the paste yields
'101.tex'.  Of course, that is what I said I wanted above, and it
should work for that particular instance, but I also want to be able
to create estimates.101 and estimates.201, for example.  That is, I
want to be able to just generate the value of sub.dataset[i] and
follow it or precede it by whatever I choose, not necessarily
quotation marks.

Thanks,

BQ

2006/4/7, Gabor Grothendieck <ggrothendieck at gmail.com>:
> See ?paste and try:
>
> paste(sub.dataset[i], "tex", sep = ".")
>
> On 4/7/06, Brian Quinif <bquinif at gmail.com> wrote:
> > I would like to use a for loop to run estimations on 12 different
> > subsets of a dataset.
> >
> > I have the basics of my script figured out, but I am having problems
> > getting the loop to name some files as I would like.   Here is a
> > sketch of my code:
> >
> > sub.dataset <- c(101, 201)
> > #Assume I only have two subsets which I call 101 and 201
> >
> > for (i in 1:length(sub.dataset)) {
> > #Estimation commands here...unimportant for this question
> > #Estimates <- matrix of estimation resultsI will write out to LaTeX
> > latex(Estimates, file=sub.dataset[i].tex)
> > }
> >
> > So, the latex command is what's problematic here.  How can I get my
> > for loop to put file='101.tex' and file='201.tex' (or many similar
> > things) where I want it to.  I could just as easily want to put
> > something like 101$variable1 or 201$variable1.
> >
> > Sorry for such a basic question regarding for loops, but thanks for the help.
> >
> > Brian
> >
> > ______________________________________________
> > R-help at stat.math.ethz.ch mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
> >
>




More information about the R-help mailing list