rmh@surfer.sbm.temple.edu
2003-Mar-04 01:04 UTC
[Rd] question on latticeParseFormula (PR#2602)
This feels like inconsistent behavior. latticeParseFormula works the way I anticipated for factor, but not for ordered. I want the behavior I see with tmp2, but not with tmp. My next step is to use the right.name to isolate the tmp2[,c("a","b")] columns. tmp <- data.frame(y=(1:12)+.1, a=factor(rep(1:3,4)), b=ordered(rep(1:4, c(3,3,3,3)))) latticeParseFormula(as.formula(y ~ a + b), data=tmp) tmp2 <- data.frame(y=(1:12)+.1, a=factor(rep(1:3,4)), b=factor(rep(1:4, c(3,3,3,3)))) latticeParseFormula(as.formula(y ~ a + b), data=tmp2)> version_ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major 1 minor 6.2 year 2003 month 01 day 10 language R> tmp <- data.frame(y=(1:12)+.1,+ a=factor(rep(1:3,4)), + b=ordered(rep(1:4, c(3,3,3,3))))> latticeParseFormula(as.formula(y ~ a + b), data=tmp)Error in a + b : non-numeric argument to binary operator> > tmp2 <- data.frame(y=(1:12)+.1,+ a=factor(rep(1:3,4)), + b=factor(rep(1:4, c(3,3,3,3))))> latticeParseFormula(as.formula(y ~ a + b), data=tmp2)$left [1] 1.1 2.1 3.1 4.1 5.1 6.1 7.1 8.1 9.1 10.1 11.1 12.1 $right [1] NA NA NA NA NA NA NA NA NA NA NA NA $condition NULL $left.name [1] "y" $right.name [1] "a + b">Rich
deepayan@stat.wisc.edu
2003-Mar-04 01:44 UTC
[Rd] question on latticeParseFormula (PR#2602)
The fact that an attempt at adding an unordered and an ordered factor gives an error 1. is not a bug (at least I can't imagine why it would be so) 2. has nothing to do with latticeParseFormula Also, I very much doubt that getting a bunch of NA's and a warning (which you seem to have omitted from your output) is really what you anticipated when you added two (unordered) factors. Please first report what you think are bugs on r-devel before filing bug reports. On Monday 03 March 2003 06:04 pm, rmh@surfer.sbm.temple.edu wrote:> This feels like inconsistent behavior. latticeParseFormula works the > way I anticipated for factor, but not for ordered. I want the > behavior I see with tmp2, but not with tmp. My next step is to use > the right.name to isolate the tmp2[,c("a","b")] columns. > > > tmp <- data.frame(y=(1:12)+.1, > a=factor(rep(1:3,4)), > b=ordered(rep(1:4, c(3,3,3,3)))) > latticeParseFormula(as.formula(y ~ a + b), data=tmp) > > tmp2 <- data.frame(y=(1:12)+.1, > a=factor(rep(1:3,4)), > b=factor(rep(1:4, c(3,3,3,3)))) > latticeParseFormula(as.formula(y ~ a + b), data=tmp2) > > > version > > _ > platform i386-pc-mingw32 > arch i386 > os mingw32 > system i386, mingw32 > status > major 1 > minor 6.2 > year 2003 > month 01 > day 10 > language R > > > tmp <- data.frame(y=(1:12)+.1, > > + a=factor(rep(1:3,4)), > + b=ordered(rep(1:4, c(3,3,3,3)))) > > > latticeParseFormula(as.formula(y ~ a + b), data=tmp) > > Error in a + b : non-numeric argument to binary operator > > > tmp2 <- data.frame(y=(1:12)+.1, > > + a=factor(rep(1:3,4)), > + b=factor(rep(1:4, c(3,3,3,3)))) > > > latticeParseFormula(as.formula(y ~ a + b), data=tmp2) > > $left > [1] 1.1 2.1 3.1 4.1 5.1 6.1 7.1 8.1 9.1 10.1 11.1 12.1 > > $right > [1] NA NA NA NA NA NA NA NA NA NA NA NA > > $condition > NULL > > $left.name > [1] "y" > > $right.name > [1] "a + b" > > > > Rich > > ______________________________________________ > R-devel@stat.math.ethz.ch mailing list > http://www.stat.math.ethz.ch/mailman/listinfo/r-devel
rmh@surfer.sbm.temple.edu
2003-Mar-04 02:11 UTC
[Rd] question on latticeParseFormula (PR#2602)
I didn't get a warning. I got exactly what I sent. The NA doesn't bother me since I am interested in parsing the expression, specifically to see what is to the left of the "~" and what is to the right of the "~". I am interested in components left.name and right.name, .I am not interested in left and right. My inference from your response is that I should work with the parse tree from parse(text="y ~ a + b") rather than continue pushing latticeParseFormula. On the other issue that you raised, I am surprised to learn that R can add factors to factors and ordered to ordered. I didn't expect either case. However, given that it can do something, I still would expect that it could add them to each other by recognizing that ordered inherits from factor.> ordered(1:3) + ordered(3:5)[1] NA NA NA> factor(1:3) + factor(3:5)[1] NA NA NA> factor(1:3) + ordered(3:5)Error in factor(1:3) + ordered(3:5) : non-numeric argument to binary operator>thank you for the prompt response. Rich