[Rd] Characters vs. factors
hadley wickham
h.wickham at gmail.com
Tue Oct 6 01:33:23 CEST 2009
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/
More information about the R-devel
mailing list