[Rd] formulas and frames

Gabor Grothendieck ggrothendieck at gmail.com
Fri Apr 1 16:56:01 CEST 2005


Try this:

my.df <- data.frame(a=1:10, b=11:20, c=21:30, d=31:40)
> model.response(model.frame(cbind(a,b) ~ c+d, my.df))
    a  b
1   1 11
2   2 12
3   3 13
4   4 14
5   5 15
6   6 16
7   7 17
8   8 18
9   9 19
10 10 20


On Apr 1, 2005 2:31 AM, Charles Geyer <charlie at stat.umn.edu> wrote:
> I have a design problem.  I'm trying to design a package that does
> something like glm, but
> 
>  1. the response is multivariate, so I can't be just like glm
>     and get the response variables out of the formula.  I decided
>     (perhaps incorrectly) to just supply the response variable
>     names as an argument "response".
> 
>  2. I have the usual predictor variables.
> 
>  3. I discovered the reshape function, which will allow me to
>     string out the data frame in long form with the response
>     strung out in a single vector.  So I can get a model matrix
>     for the right hand side of the formula, which can also include
>     what reshape calls the time variable (although it isn't time).
> 
> so far so good, but
> 
>  4. Each response variable is conditioned on a "predecessor" variable.
> 
> so we come to my question.  How do I force a bunch of variables into
> a data frame?  I need all of the "response" and "predecessor" variables,
> which are at this point specified only by a character vector containing
> their names (or something else???) and I also need all of the predictor
> variables.  If the user has supplied a data frame containing all that
> stuff fine!  But if it's just all over the place, some in the "data"
> argument and some in the R global environment (or elsewhere???).
> Maybe I'm just ignorant, but I haven't stumbled across a function that
> just stuffs all that stuff into a data frame (model.frame would do it
> if I didn't have this extra stuff).
> 
> Any help?  Or do I just have to kludge this?
> 
> --
> Charles Geyer
> Professor, School of Statistics
> University of Minnesota
> charlie at stat.umn.edu
> 
> ______________________________________________
> R-devel at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



More information about the R-devel mailing list