[Rd] stringsAsFactors = FALSE
hadley wickham
h.wickham at gmail.com
Mon Nov 17 18:34:02 CET 2008
On Mon, Nov 17, 2008 at 11:06 AM, William Dunlap <wdunlap at tibco.com> wrote:
>> From: r-devel-bounces at r-project.org
>> [mailto:r-devel-bounces at r-project.org] On Behalf Of hadley wickham
>> Sent: Monday, November 17, 2008 5:10 AM
>> To: r-devel at r-project.org
>> Subject: [Rd] stringsAsFactors = FALSE
>> ...
>> The key lines in
>> expand.grid would seem to be
>>
>> if (!is.factor(x) && is.character(x))
>> x <- factor(x, levels = unique(x))
>>
>> but I'm not sure why they are being converted to factors in
>> the first place.
>
> I think expand.grid converts input strings to factors so they
> retain the order they have in the input. (Note that the levels
> argument is unique(x), not the sort(unique(x)) that data.frame uses.)
> People generally give expand.grid sorted input and expect it to
> not alter the order (the order of the levels affects tables and
> and some plots).
Ah, that makes sense. (Although the conversion to factors just seems
to be a convenient way to achieve the desired effect in this case -
there's no reason they have to be factors in the output)
Hadley
--
http://had.co.nz/
More information about the R-devel
mailing list