> r[1] open settle <0 rows> (or 0-length row.names)> class(r)[1] "data.frame" this is an empty data.frame I get back from a sql statement that returns an empty result set. How can I create such an empty data.frame using the data.frame() constructor? I want to have a data.frame with 0 rows but named empty columns. Thanks in advance for any help.
On 4/28/05, Omar Lakkis <uofiowa@gmail.com> wrote:> > > r > [1] open settle > <0 rows> (or 0-length row.names) > > class(r) > [1] "data.frame" > > this is an empty data.frame I get back from a sql statement that > returns an empty result set. How can I create such an empty data.frame > using the data.frame() constructor? > I want to have a data.frame with 0 rows but named empty columns.> data.frame(a = numeric(0), b = numeric(0)) [1] a b <0 rows> (or 0-length row.names) [[alternative HTML version deleted]]
On Thu, 28 Apr 2005, Omar Lakkis wrote:>> r > [1] open settle > <0 rows> (or 0-length row.names) >> class(r) > [1] "data.frame" > > this is an empty data.frame I get back from a sql statement that > returns an empty result set. How can I create such an empty data.frame > using the data.frame() constructor? > I want to have a data.frame with 0 rows but named empty columns.Is this what you want?> x <- data.frame(a=character(0), b=numeric(0)) > x[1] a b <0 rows> (or 0-length row.names)> names(x)[1] "a" "b" -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595