From ripley at stats.ox.ac.uk  Fri Sep 21 15:11:29 2007
From: ripley at stats.ox.ac.uk (ripley at stats.ox.ac.uk)
Date: Fri, 21 Sep 2007 15:11:29 +0200 (CEST)
Subject: [Rd] (PR#9917) rbind.data.frame converts character column to
Message-ID: <20070921131129.3BD1A66905@slim.kubism.ku.dk>

  This message is in MIME format.  The first part should be readable text,
  while the remaining parts are likely unreadable without MIME-aware tools.

--27464147-159404577-1190380210=:1425
Content-Type: TEXT/PLAIN; charset=iso-8859-1; format=flowed
Content-Transfer-Encoding: 8BIT

Please do read the documentation, which says

      The 'rbind' data frame method first drops all zero-column and
      zero-row arguments.

So your first data frame has been dropped, and the result is the same as
rbind.data.frame(list(a = "foo")) which should give a factor column via 
promotion of a list to a data frame.


On Tue, 18 Sep 2007, sebastien.villemot at ens.fr wrote:

> Full_Name: S?bastien Villemot
> Version: 2.5.1
> OS: Debian GNU/Linux (Testing aka "Lenny")
> Submission from: (NULL) (193.51.127.120)
>
>
> Here is the transcript of a R session under version 2.5.1:
>
>> x <- data.frame(a = I(character(0)))
>> typeof(x$a)
> [1] "character"
>> x <- rbind(x, list(a = "foo"))
>> typeof(x$a)
> [1] "integer"
>
> The column "a" has been converted from character to factor.
>
> This was not happening under version 2.4.0 Patched (2006-11-25 r39997):
>> x <- data.frame(a = I(character(0)))
>> typeof(x$a)
> [1] "character"
>> x <- rbind(x, list(a = "foo"))
>> typeof(x$a)
> [1] "character"
>
> Furthermore, the bug doesn't show up (in 2.5.1) if the data frame is initially
> non-empty:
>> x <- data.frame(a = I("bar"))
>> typeof(x$a)
> [1] "character"
>> x <- rbind(x, list(a = "foo"))
>> typeof(x$a)
> [1] "character"
>
> Best,
>
> S?bastien Villemot
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

-- 
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
--27464147-159404577-1190380210=:1425--



[Rd] (PR#9917) rbind.data.frame converts character column to
ripley at stats.ox.ac.uk