From rowe at muxspace.com  Tue Feb 12 17:05:55 2013
From: rowe at muxspace.com (Brian Lee Yung Rowe)
Date: Tue, 12 Feb 2013 11:05:55 -0500
Subject: [Rd] Regression stars
In-Reply-To: <511A6286.4040704@gmail.com>
References: <20130209184801.GD14037@laura>
	<CAC+N9BXeaBzBMGidTJbrBT_hjKM0fW5ey6EWBSBbVqk12LZXGQ@mail.gmail.com>
	<CAC+N9BVRxcWLtGwHGbBD=4=uAPSan4jEFYfOWsLLqV4FrSyLGA@mail.gmail.com>
	<51180503.1080605@gmail.com>
	<loom.20130212T145313-215@post.gmane.org>
	<511A4F98.50209@statistik.tu-dortmund.de>
	<511A6286.4040704@gmail.com>
Message-ID: <02F28BE5-04D2-44A8-920D-6E957CCDC4C7@muxspace.com>


I thought that the default was the way it was for performance reasons. For large data.frames or repeated applications, using factors should be faster for non-trivial strings.

> fs <- c('apple','peach','watermelon','spinach','persimmon','potato','kale')
> n <- 1000000
>
> a1 <- data.frame(f=sample(fs,n,replace=TRUE), x1=rnorm(n), x2=rnorm(n), stringsAsFactors=TRUE)
> a2 <- data.frame(f=sample(fs,n,replace=TRUE), x1=rnorm(n), x2=rnorm(n), stringsAsFactors=FALSE)
>
> fn <- function(i,x) x[x$f %in% c('kale','spinach'),]
> system.time(z <- sapply(1:100, fn, a1))
   user  system elapsed 
 19.614   4.037  24.649 
> system.time(z <- sapply(1:100, fn, a2))
   user  system elapsed 
 19.726   7.715  36.761 


On Feb 12, 2013, at 10:40 AM, Ben Bolker <bbolker at gmail.com> wrote:
> 
>  Thanks, Uwe.
>  Now let me go one step farther.
> 
>  Can you (or anyone) give a good argument **other than backward
> compatibility** for keeping the stringAsFactors=TRUE argument on
> data.frame()?
> 
>  I appreciate your distinction between data.frame() and read.table()'s
> use of stringAsFactors, and I can see that there is some point for
> quick-and-dirty interactive use in setting all non-numeric variables to
> factors (arguing that wanting non-numerics as factors is somewhat more
> common than wanting them as strings).
> 
>  It might be nice to add an optional stringsAsFactors (and check.names)
> argument to transform(): I've had to write my own Transform() function
> to allow the defaults to be overridden, since transform() calls
> data.frame() with the defaults.  (Setting the stringsAsFactors option
> globally would work, although not for check.names.)
> 
>  Ben BOlker
> 
>> 
>>> 
>>>> What I will likely do is
>>>> make a few changes so that character vectors are automatically changed
>>>> to factors in modelling functions, so that operating with
>>>> stringsAsFactors=FALSE doesn't trigger silly warnings.
>>>> 
>>>> Duncan Murdoch
>>>> 
>>> 
>>>  [apologies for snipping context: "gmane made me do it"]
>>> 
>>> ______________________________________________
>>> R-devel at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>> 
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] Regression stars
Brian Lee Yung Rowe