Ravi Varadhan
2002-Dec-13 18:20 UTC
[R] How to get objects from a "formula" specification?
Hi: I'd like to get the objects corresponding to the elements in a formula, from a data frame. For example, suppose I would like to make a function call, such as follows: myfunc(formula="y ~ x1 + x2 + log(x3)" , data=mydata) This function will get the vector objects y, x1, x2, and log(x3) from the data frame "mydata" to form the design matrix and then perform a maximum likelihood estimation of the regression parameters. My questions is, how do I get the the vector objects y, x1, x2, and log(x3),specified the formula, from the data frame "mydata"? thanks for any help, Ravi.
ripley@stats.ox.ac.uk
2002-Dec-13 18:45 UTC
[R] How to get objects from a "formula" specification?
?model.frame ?model.matrix `S Programming' by Venables & Ripley (2000). On Fri, 13 Dec 2002, Ravi Varadhan wrote:> Hi: > > I'd like to get the objects corresponding to the elements in a formula, > from a data frame. For example, suppose I would like to make a > function call, such as follows: > > myfunc(formula="y ~ x1 + x2 + log(x3)" , data=mydata) > > This function will get the vector objects y, x1, x2, and log(x3) from > the data frame "mydata" to form the design matrix and then perform a > maximum likelihood estimation of the regression parameters. > > My questions is, how do I get the the vector objects y, x1, x2, and > log(x3),specified the formula, from the data frame "mydata"?BTW, that's not precisely how formulae in R work. -- 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 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595
Ravi Varadhan
2002-Dec-13 19:50 UTC
[R] How to get objects from a "formula" specification?
I'd like to thank Prof. Ripley and Andy Liaw for their solution to my question. They suggested using "model.frame" or "model.matrix" Best, Ravi. ----- Original Message ----- From: ripley at stats.ox.ac.uk Date: Friday, December 13, 2002 12:44 pm Subject: Re: [R] How to get objects from a "formula" specification?> ?model.frame > ?model.matrix > > `S Programming' by Venables & Ripley (2000). > > On Fri, 13 Dec 2002, Ravi Varadhan wrote: > > > Hi: > > > > I'd like to get the objects corresponding to the elements in a > formula,> from a data frame. For example, suppose I would like to > make a > > function call, such as follows: > > > > myfunc(formula="y ~ x1 + x2 + log(x3)" , data=mydata) > > > > This function will get the vector objects y, x1, x2, and log(x3) > from> the data frame "mydata" to form the design matrix and then > perform a > > maximum likelihood estimation of the regression parameters. > > > > My questions is, how do I get the the vector objects y, x1, x2, and > > log(x3),specified the formula, from the data frame "mydata"? > > BTW, that's not precisely how formulae in R work. > > -- > 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 272860 (secr) > Oxford OX1 3TG, UK Fax: +44 1865 272595 > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > http://www.stat.math.ethz.ch/mailman/listinfo/r-help >
Possibly Parallel Threads
- A faster way to compute finite-difference gradient of a scalar function of a large number of variables
- X-axis labels in histograms drawn by the "truehist" function
- Difficulty in calculating MLE through NLM
- A easy way to write formula
- Non-negative solutions to complicated equations