[R] Naming dataframes, vectors etc within a loop

Henrik Bengtsson hb at stat.berkeley.edu
Wed Aug 13 05:23:24 CEST 2008


See help(list) and help("[[") ...and 'An Introduction to R'.

/Henrik

On Tue, Aug 12, 2008 at 7:49 PM, Gareth Campbell <gcam032 at gmail.com> wrote:
> Hi there,
>
> I know this is probably a really simple question, but without the correct
> keywords, or knowledge of the correct function it is hard to search for on
> the net or within R.
>
> How do I increment a dataframe (or similar) name within a loop and assign
> data?
>
> A simple example would be:
>
> for(i in 1:10){
>    test<-i
> }
>
> BUT I want it to be test[i]   ---   in other words I want my stored data to
> be in this form:
>
> test.1<-1
> test.2<-2
> test.3<-3... and so on.
>
> I have tried doing things like:
>
> test.i
> test[i]
> and have tried a paste command, for example
>
> paste("test",i, sep="")
>
> but this turns it into a factor and you cannot assign the data or anything.
>
> Thanks in advance.
>
> --
> Gareth Campbell
> PhD Candidate
> The University of Auckland
>
> P +649 815 3670
> M +6421 256 3511
> E gareth.campbell at esr.cri.nz
> gcam032 at gmail.com
>
>        [[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