Message-ID: <CAP01uR=2xwA6Zd0mzieR-Ve3z5Pv+iGs=b3=XPA1NU8Pn4UyKw@mail.gmail.com>
Date: 2012-07-11T13:09:19Z
From: Gabor Grothendieck
Subject: fill 0-row data.frame with 1 line of NAs
In-Reply-To: <CABxs9Vn5NHMSmY7TdL3CQjyPv6vTd_wB=oBtOjXqmaKoZSAS9Q@mail.gmail.com>
On Tue, Jul 10, 2012 at 9:15 AM, Liviu Andronic <landronimirc at gmail.com> wrote:
> Dear all
> Is there a simpler method to achieve the following: When I obtain an
> empty data.frame after subsetting, I need for it to contain one line
> of NAs. Here's a dummy example:
>> (.xb <- iris[ iris$Species=='zz', ])
> [1] Sepal.Length Sepal.Width Petal.Length Petal.Width Species
> <0 rows> (or 0-length row.names)
>> dim(.xb)
> [1] 0 5
>> (.xa <- data.frame(matrix(rep(NA, ncol(.xb)), 1)))
> X1 X2 X3 X4 X5
> 1 NA NA NA NA NA
>> names(.xa) <- names(.xb)
>> (.xb <- .xa)
> Sepal.Length Sepal.Width Petal.Length Petal.Width Species
> 1 NA NA NA NA NA
>
>
> The solution I came up with is way too convoluted. Anything simpler? Regards
> Liviu
>
Try this:
Try this:
> iris[NaN,]
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
NA NA NA NA NA <NA>
--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com