R-beta: R 0.61.1 model.matrix(), etc.
Peter Dalgaard BSA
p.dalgaard at biostat.ku.dk
Mon Jul 6 00:07:46 CEST 1998
Rashid Nassar <rnassar at acpub.duke.edu> writes:
> 2. The following may or may not be (minor) bugs, but I thought I'd mention
> them anyway:
>
> (a) model.matrix() seems unduly finicky: it seems to accept only "simple"
> variable names (x1, but not, say, dframe$x1 or I(x1^2), for example) in
> its argument. model.frame(), however, has no problem with these.
Yep. In fact using model.frame() inside model.matrix.default seems to
help quite a bit:
R> model.matrix.default
function (formula, data, contrasts = NULL)
{
t <- terms(formula)
if (missing(data)) {
vars <- attr(t, "variables")
# comes out as list(x,y,z), make it data.frame(x,y,z)
vars[[1]] <- as.name("data.frame")
data <- eval(vars, sys.frame(sys.parent()))
}
else if (is.null(attr(data, "terms")))
data <- model.frame(formula, data)
replace the 'then' clause (within {}s) with
data<-model.frame(formula)
and the behaviour goes away.
Data.frame is being "helpful" and converts names like "exp(x)" into
"exp.x." which causes the trouble later on. (It's debatable whether
that is really smart, but it's S-plus compatible.)
(fixed in intermediate patch version)
> (b) If A is a factor, "mode(A)" returns "numeric", and both "is.numeric(A)"
> and "is.factor(A)" return "TRUE".
This, however, is exactly as in S-plus. There is some sense of logic
in it since factors are really just integers with some particular
attributes:
R> dput(factor(1:5))
structure(c(1, 2, 3, 4, 5), .Label = c("1", "2", "3", "4", "5"
), class = "factor")
--
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list