Skip to content
Prev 308653 / 398503 Next

What is behind class coercion of a factor into a character

Tal:

There was a recent discussion on this list about this (Sam Steingold
was the OP IIRC).

The issue is ?c . In particular:

"c is sometimes used for its side effect of removing attributes except
names, for example to turn an array into a vector."

Hence, the factor attribute is removed and you get what you saw. As
regards it's "rationale," you may find Bill Dunlap's comments on
"c()'s unfortunate history" relevant. The problem with factors is
"what should concatenation do, anyway?" If a <- factor(c("x", "y"))
and b <- factor(c("y", "z")), what should c(a,b) be? -- There is no
reason to assume that the "y" in a is the same as the "y" in b!

Cheers,
Bert
On Mon, Oct 22, 2012 at 6:46 AM, Tal Galili <tal.galili at gmail.com> wrote: