Dear All,

on rbind:ing together a number of data.frames, I found that
character variables are converted into factors. Since this
occurred for a data identifier, it was a little inconvenient
and, to me, unexpected. (The help page explains the
general procedure used. I also found that on forming 
a data frame, character variables are converted to factors.

The help page on read.table has the 'as.is' argument, which
I suppose kind of suggests that character variables  tend to
get converted into factors. Is there such a "preference" for 
factors and should this behaviour be expected?

Example code

 d1 <- data.frame(id =letters[1:20], x = runif(20))
d2 <- data.frame(id =paste(letters[1:20],letters[1:20], sep = ""),  x =
rexp(20))
d3 <- rbind(d1, d2)
str(d1) # <- id is factor
str(d2) # <- id is factor
str(d3) # <- id is factor
d1[["id"]] <- as.character(d1[["id"]])
d2[["id"]] <- as.character(d2[["id"]])
d3 <- rbind(d1, d2)
str(d1) # <- id is character
str(d2) # <- id is character
str(d3) # <- id is factor

Regards,

Markus
-- 
Markus Jäntti <[EMAIL PROTECTED]>
Statistics Finland

______________________________________________
[EMAIL PROTECTED] mailing list
http://www.stat.math.ethz.ch/mailman/listinfo/r-help

Reply via email to