[R] creating files using for loop

Gabor Grothendieck ggrothendieck at gmail.com
Fri Apr 7 06:24:50 CEST 2006


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