From h.wickham at gmail.com  Tue Oct  6 01:33:23 2009
From: h.wickham at gmail.com (hadley wickham)
Date: Mon, 5 Oct 2009 18:33:23 -0500
Subject: [Rd] Characters vs. factors
Message-ID: <f8e6ff050910051633v55fc01b6i5ab9ab2ff201eff9@mail.gmail.com>

It seems like a recent trend in R has been to make character vectors
and factors almost equivalent (apart from the way that factors always
remember their original range).  There are a few exceptions:

 * summary.character != summary.factor
 * table(x, exclude = NULL) != table(factor(x), exclude=NULL) when x
includes missing values

 * strsplit on a factor

> strsplit(factor(c("a", "a b")), " ")
Error in strsplit(factor(c("a", "a b")), " ") : non-character argument

 * nchar on a factor:

> nchar(factor(c("abc", "d", "defgh")))
[1] 1 1 1

 * : with two character strings

> "a":"b"
Error in "a":"b" : NA/NaN argument
In addition: Warning messages:
1: NAs introduced by coercion
2: NAs introduced by coercion
> factor("a"):factor("b")
[1] a:b
Levels: a:b

Regards,

Hadley

-- 
http://had.co.nz/



[Rd] Characters vs. factors
hadley wickham