[Rd] rbind.data.frame converts character column to factor (PR#9917)

From: <sebastien.villemot_at_ens.fr>
Date: Tue, 18 Sep 2007 18:37:44 +0200 (CEST)


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 Received on Fri 21 Sep 2007 - 12:27:12 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 21 Sep 2007 - 12:41:29 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.