[R] How can I create a data.table with 1000 variables (Var1:Var1000)

Ista Zahn istazahn at gmail.com
Thu Aug 15 23:19:22 CEST 2013


On Thu, Aug 15, 2013 at 5:09 PM, Pooya Lalehzari
<plalehzari at platinumlp.com> wrote:
>
> Here is the sample code.
>
> Large_Table = data.frame(
>                   Var1=numeric(),
>                         Var2=numeric(),
>                         Var3=numeric(),
>                         .
>                         .
>                         .
>                         Var1000=numeric())
> Ideally, I would like to say
> Large_Table = data.frame(
>                   Var1-Var1000=numeric()
>                         )


One way is to create a matrix of the desired dimensions and convert it
to a data.frame, e.g

data.frame(matrix(nrow = 0, ncol=1000, dimnames = list(c(),
paste("Var", 1:1000))))

Best,
Ista

>
> Or maybe the answer is not to declare them and just create the variables as needed (i.e. in the for-loop that will use the data.frame.)
>
>
> -----Original Message-----
> From: arun [mailto:smartpink111 at yahoo.com]
> Sent: Thursday, August 15, 2013 5:04 PM
> To: Pooya Lalehzari
> Subject: Re: [R] How can I create a data.table with 1000 variables (Var1:Var1000)
>
> This question is still not clear.  Could you show a reproducible example as to what you want?  In the title, it says to create 1000 variable and now your explanation is "refer".  Also, it is unclear as to what function in SAS you are referring to.  As Bert said, please follow the posting guide while posting.
> Best.
>
>
>
>
> ----- Original Message -----
> From: Pooya Lalehzari <plalehzari at platinumlp.com>
> To: Bert Gunter <gunter.berton at gene.com>
> Cc: "r-help at r-project.org" <r-help at r-project.org>
> Sent: Thursday, August 15, 2013 4:27 PM
> Subject: Re: [R] How can I create a data.table with 1000 variables (Var1:Var1000)
>
> Sorry. data.table or even data.frame (as they are related). My question is, if there is a short form to refer to all 1000 of them similar to what exists in SAS.
>
> Thank you,
> Pooya Lalehzari.
>
>
> -----Original Message-----
> From: Bert Gunter [mailto:gunter.berton at gene.com]
> Sent: Thursday, August 15, 2013 4:24 PM
> To: Pooya Lalehzari
> Cc: r-help at r-project.org
> Subject: Re: [R] How can I create a data_table with 1000 variables (Var1:Var1000)
>
> Please:
>
> 1. Define "data_table"  (??)
>
> 2. Follow the advice from the posting guide link below to post a coherent question.
>
> -- Bert
>
> On Thu, Aug 15, 2013 at 1:16 PM, Pooya Lalehzari <plalehzari at platinumlp.com> wrote:
> > Hello everyone,
> > How can I create a data_table with 1000 variables (Var1:Var1000)?
> >
> > Thank you,
> > Pooya Lalehzari
> >
> >
> >
> > THIS E-MAIL IS FOR THE SOLE USE OF THE INTENDED RECIPIENT(S) AND MAY
> >CONTAIN CONFIDENTIAL AND PRIVILEGED INFORMATION.ANY UNAUTHORIZED
> >REVIEW, USE, DISCLOSURE OR DISTRIBUTION IS PROHIBITED. IF YOU ARE NOT
> >THE INTENDED RECIPIENT, PLEASE CONTACT THE SENDER BY REPLY E-MAIL AND DESTROY ALL COPIES OF THE ORIGINAL E-MAIL.
> >         [[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.
>
>
>
> --
>
> Bert Gunter
> Genentech Nonclinical Biostatistics
>
> Internal Contact Info:
> Phone: 467-7374
> Website:
> http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm
>
>
>
> THIS E-MAIL IS FOR THE SOLE USE OF THE INTENDED RECIPIENT(S) AND MAY CONTAIN
> CONFIDENTIAL AND PRIVILEGED INFORMATION.ANY UNAUTHORIZED REVIEW, USE, DISCLOSURE
> OR DISTRIBUTION IS PROHIBITED. IF YOU ARE NOT THE INTENDED RECIPIENT, PLEASE
> CONTACT THE SENDER BY REPLY E-MAIL AND DESTROY ALL COPIES OF THE ORIGINAL E-MAIL.
> ______________________________________________
> 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.
>
>
>
>
> THIS E-MAIL IS FOR THE SOLE USE OF THE INTENDED RECIPIENT(S) AND MAY CONTAIN
> CONFIDENTIAL AND PRIVILEGED INFORMATION.ANY UNAUTHORIZED REVIEW, USE, DISCLOSURE
> OR DISTRIBUTION IS PROHIBITED. IF YOU ARE NOT THE INTENDED RECIPIENT, PLEASE
> CONTACT THE SENDER BY REPLY E-MAIL AND DESTROY ALL COPIES OF THE ORIGINAL E-MAIL.
>
> ______________________________________________
> 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