On Mon, Nov 17, 2008 at 11:06 AM, William Dunlap <[EMAIL PROTECTED]> wrote: >> From: [EMAIL PROTECTED] >> [mailto:[EMAIL PROTECTED] On Behalf Of hadley wickham >> Sent: Monday, November 17, 2008 5:10 AM >> To: r-devel@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/ ______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel