[R] Empty data frame does not maintain column type

N David Brown hubdave at gmail.com
Wed Oct 6 19:00:48 CEST 2010


Does anyone know why a data frame created with empty character columns
converts them to integer columns?

> df<-data.frame(a=character(0),b=character(0))
> df<-rbind(df,c("a","a"))
> typeof(df[1,1])
[1] "integer"

AsIs doesn't help:

> df<-data.frame(a=I(character(0)),b=I(character(0)))
> df<-rbind(df,I(c("a","a")))
> typeof(df[1,1])
[1] "integer"

Any suggestions on how to overcome this would be appreciated.

Best wishes,

David



More information about the R-help mailing list