At times we want to convert a two-sided formula to a one-sided formula. In S we can do this by dropping the second entry in the formula. In R that object no longer has a formula class. R> ttt <- score ~ age | Infant R> class(ttt) [1] "formula" R> length(ttt) [1] 3 R> ttt[-2] [[1]] ~ [[2]] age | Infant R> class(ttt[-2]) NULL R> do.call("~", ttt[-(1:2)]) ~age | Infant In general it would not be a good idea to propagate the formula class to subsets but it does make sense in this case. We can get around it by replacing ttt[-2] by do.call("~", ttt[-(1:2)]) I suppose. Any opinions on whether ttt[-2] should still be a formula? -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel 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-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Douglas Bates <bates@stat.wisc.edu> writes:> In general it would not be a good idea to propagate the formula class > to subsets but it does make sense in this case. We can get around it > by replacing ttt[-2] by do.call("~", ttt[-(1:2)]) I suppose. Any > opinions on whether ttt[-2] should still be a formula?Hum. tt[-i] is a well-defined formula iff (i != 1). Somehow, I dislike the idea of properties depending on the value of a parameter, so I'm inclined to say no. BTW, eval(as.call(ttt[-2])) also works. And one would *think* that formula(as.call(ttt[-2])) did too, but typeof(as.call(...))==language and !=call (is this weird or not?), so formula.default protests. -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel 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-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Reasonably Related Threads
- R-alpha: model.matrix misbehaves on two-sided formulas
- t value two.sided and one.sided
- source() behavior I don't understand
- How would I color points conditional on their value in a plot of a time series
- How would I color points conditional on their value in a plot of a time series