[R] Sorting data for multiple regressions

Prof Brian Ripley ripley at stats.ox.ac.uk
Sat Aug 4 07:49:16 CEST 2007

Well, R has a by() function that does what you want, and its help page 
contains an example of doing regression by group.

(There are other ways.)

On Fri, 3 Aug 2007, Paul Young wrote:

> So I am trying to perform a robust regression (fastmcd in the robust
> package) on a dataset and I want to perform individual regressions based

fastmcd does not do regression ... or I would have adapted the ?by 
example to show you.

> on the groups within the data.  We have over 300 sites and we want to
> perform a regression based on the day of week and the hour for every
> site.  I was wondering if anyone knows of a "'by' command similar to the
> one used in SAS that automatically groups the data for the regressions.
> If not, does anyone have any tips on how to split the data into smaller
> sets and then perform the regression on each set.  I am new to R, so I
> don't know all of the common work arounds and such.  At the moment the
> only method I can think of is to split the data using condition
> statements and manually running the regression on each set.  Thanks or
> your help
> -Paul

Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

More information about the R-help mailing list