For reasons best known only to myself ( :-) ) I wish to create a data frame with 0 rows and 9 columns. The best I've been able to come up with is: junk <- as.data.frame(matrix(0,nrow=0,ncol=9)) Is there a sexier way? cheers, Rolf ###################################################################### Attention:\ This e-mail message is privileged and confid...{{dropped:9}}
Check out this thread: https://stat.ethz.ch/pipermail/r-help/2008-February/153638.html On Feb 19, 2008 10:47 PM, Rolf Turner <r.turner at auckland.ac.nz> wrote:> > For reasons best known only to myself ( :-) ) I wish to create a data > frame with 0 rows and 9 columns. > > The best I've been able to come up with is: > > junk <- as.data.frame(matrix(0,nrow=0,ncol=9)) > > Is there a sexier way? > > cheers, > > Rolf > > ###################################################################### > Attention:\ This e-mail message is privileged and confid...{{dropped:9}} > > ______________________________________________ > 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. >
Rolf Turner wrote:> For reasons best known only to myself ( :-) ) I wish to create a data > frame with 0 rows and 9 columns. > > The best I've been able to come up with is: > > junk <- as.data.frame(matrix(0,nrow=0,ncol=9)) > > Is there a sexier way?I'm unsure of their virtue or seediness, but here are some alternatives: > data.frame(a=numeric(0), b=numeric(0)) # include 9 arguments if you like [1] a b <0 rows> (or 0-length row.names) > as.data.frame(rep(list(a=numeric(0)), 9)) [1] a a.1 a.2 a.3 a.4 a.5 a.6 a.7 a.8 <0 rows> (or 0-length row.names) > -- Tony Plate> > cheers, > > Rolf > > ###################################################################### > Attention:\ This e-mail message is privileged and confid...{{dropped:9}} > > ______________________________________________ > 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. >