Re: [R] initialize a factor vector

From: Johannes Huesing <>
Date: Sat, 19 Jul 2008 15:20:28 +0200

I have found that factor vectors are shy beasts.


> empty <- factor(levels=c("eins", "zwei"))
> value <- factor("eins", levels=c("eins", "zwei"))
> c(empty, value)

[1] 1
> empty[1] <- value
> empty

[1] eins
Levels: eins zwei

I could not exactly predict this behaviour, but ?c says:

    The output type is determined from the highest type of the

     components in the hierarchy NULL < raw < logical < integer < real
     < complex < character < list < expression. 

As factor is a class (of the whole vector) and not a type (of a single element), c does not seem to preserve the object information, i.e. there does not seem to be a c.factor, correct?

Johannes Hüsing               There is something fascinating about science. 
                              One gets such wholesale returns of conjecture  from such a trifling investment of fact.                (Mark Twain, "Life on the Mississippi")

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Sat 19 Jul 2008 - 13:23:33 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 Sat 19 Jul 2008 - 16:31:49 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive