From spencer.graves at prodsyse.com  Tue Oct  4 01:59:07 2016
From: spencer.graves at prodsyse.com (Spencer Graves)
Date: Mon, 3 Oct 2016 18:59:07 -0500
Subject: [Rd] suggested addition to model.matrix
Message-ID: <37d127c5-2137-e077-61af-6cbe1b6cad47@prodsyse.com>

Hello, All:


       What's the simplest way to convert a data.frame into a model.matrix?


       One way is given by the following example, modified from the 
examples in help(model.matrix):


dd <- data.frame(a = gl(3,4), b = gl(4,1,12))
ab <- model.matrix(~ a + b, dd)
ab0 <- model.matrix(~., dd)
all.equal(ab, ab0)


       What do you think about replacing "model.matrix(~ a + b, dd)" in 
the current help(model.matrix) with this 3-line expansion?


       I suggest this, because I spent a few hours today trying to 
convert a data.frame into a model.matrix before finding this.


       Also, what do you think about adding something like the following 
to the stats package:


model.matrix.data.frame <- function(object, ...){
     model.matrix(~., object, ...)
}


       And then extend the above example as follows:

ab. <- model.matrix(dd)
all.equal(ab, ab.)


       Thanks,
       Spencer Graves



[Rd] suggested addition to model.matrix
Spencer Graves