Skip to content

Using a by() function to process several regression (lm()) functions

1 message · Charlie Sharpsteen

#
On Thu, Nov 5, 2009 at 11:15 PM, Marc Los Huertos <mloshuertos at csumb.edu> wrote:
do.call() is an incredibly useful function-- I was able to do data
processing much more efficiently after I found it.  Basically, it
takes two arguments-- a function and a list.  The function is called
and the list is used as the arguments.  Since rbind() takes an
arbitrarily long list of objects, using do.call and rbind() or cbind()
is a quick way to collapse a list into a matrix or data.frame.  If the
function takes named arguments, such as pf(), do.call will match the
names in the list with the names of the arguments-- this is the reason
for all the monkey business I pulled by:

  1. Extracting the parameters of the F-distribution from a summary of
the linear model.
  2. Converting them from a vector to a list.
  3. Renaming them so that they matched the arguments to pf()
This looks like a much more efficient method!
I believe this is just the convention that Hadley decided to use in
the plyr package.  Another incredibly useful package of his that you
may want to check out for data processing is 'reshape'.  It is based
on plyr and uses some of the same conventions.  You can find good
documentation, examples and papers concerning his R packages on his
website:

  http://had.co.nz/
No problem, have fun busting that data apart!

-Charlie