[R] Coercing data types for use in model.frame
Gabor Grothendieck
ggrothendieck at gmail.com
Wed Apr 25 14:00:35 CEST 2007
You could try to follow the code in the dyn package. It intercepts
model.frame calls involving time series objects so that it can align
lagged objects:
e.g.
z <- ts(seq(10)^2)
library(dyn)
dyn$lm(z ~ lag(z, -1))
It transforms the last line above to:
dyn(lm(dyn(z ~ lag(z, -1)))
and the inner dyn then produces a formula with class c("dyn", "model.frame")
so that model.frame.dyn can intercept the call while the outer dyn adds
"dyn" to the class of the result so that anova.dyn, predict.dyn, etc. can be
used to intercept the result.
Thus for any lm-like function you just preface it with dyn$ as shown and
you get automatically alignment of time series or in your case you would
interception of the mChoice variables.
On 4/24/07, Frank E Harrell Jr <f.harrell at vanderbilt.edu> wrote:
> In the Hmisc package there is a new data class 'mChoice' for multiple
> choice variables. There are format and as.numeric methods (the latter
> creates a matrix of dummy variables). mChoice variables are not allowed
> by model.frame. Is there a way to specify a conversion function that
> model.frame will use automatically? I would use as.factor here.
> model.frame does not seem to use as.data.frame.foo for individual variables.
>
> Thanks
> Frank
> --
> Frank E Harrell Jr Professor and Chair School of Medicine
> Department of Biostatistics Vanderbilt University
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
More information about the R-help
mailing list