Re: [R] how to construct an empty data.frame

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Fri 29 Apr 2005 - 03:38:17 EST

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@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

______________________________________________
R-help@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
Received on Fri Apr 29 03:41:55 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:28 EST