[S] use of model.matrix within another function

K. Oudshoorn (k.oudshoorn@pg.tno.nl)
Wed, 28 Oct 1998 10:43:35 +0000


Dear S-Plus users,

I have the following question:

In a function (say name.function) a dataframe, called
data, is an argument of that function. So the call is
name.function(data).
"data" is a dataframe with possible a number of colums that are
categorical variabels. Since in name.function I want to use a
regression the dataframe "data" has to be enlarged with dummy
variables for the categorical variabels. The way I thougth this would
work is to use the function model.matrix.
So suppose the column data[,2] is categorical. Then with
model.matrix(~data[,2]-1)
one can create dummy variables (without intercept) for the
categorical variable. If I try this out on the commandline it works.
But when I use this command in the function name.function there
appears an error:

Error in [: N dim attribute for array subset : list( ..

Can anyone tell me what goes wrong and way? And besides that what is
the right way to handle this thing?

Thanks in advance,

Karin Oudshoorn

ps. I do not want to use the function lm() that creates itself the
dummies since I really need the dataframe data with the dummy's as
extra columns

--------------------------------------------------
Karin Oudshoorn
TNO Preventie en Gezondheid
tel: 071- 5181756
mailto: K.Oudshoorn@pg.tno.nl
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news