This is admittedly a contrived example, but... data(housing, package ="MASS") x <- housing$Type + housing$Sat match(x, unique(x)) Hadley -- http://had.co.nz/
Did you leave out the warning from "+", which should be an error, as it produces an illegal ordered factor in this case and factor+factor is nonsensical? Or is the warning missing in the current development version of R?> x <- factor("A", ordered=FALSE) + factor(c("B","C"), ordered=TRUE)Warning message: Incompatible methods ("Ops.factor", "Ops.ordered") for "+"> str(x) # 2 levels, so integer codes of 3 is illegalordered[1:2] w/ 2 levels B<C: 2 3 Bill Dunlap TIBCO Software wdunlap tibco.com On Mon, Mar 30, 2015 at 1:10 PM, Hadley Wickham <h.wickham at gmail.com> wrote:> This is admittedly a contrived example, but... > > data(housing, package ="MASS") > x <- housing$Type + housing$Sat > match(x, unique(x)) > > Hadley > > -- > http://had.co.nz/ > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >[[alternative HTML version deleted]]
For consistency with factor+factor and factor+numeric, factor+ordered should produce a logical vector filled with NAs, not throw an error. Bill Dunlap TIBCO Software wdunlap tibco.com On Mon, Mar 30, 2015 at 1:50 PM, William Dunlap <wdunlap at tibco.com> wrote:> Did you leave out the warning from "+", which should be an error, > as it produces an illegal ordered factor in this case and factor+factor > is nonsensical? Or is the warning missing in the current development > version of R? > > > x <- factor("A", ordered=FALSE) + factor(c("B","C"), ordered=TRUE) > Warning message: > Incompatible methods ("Ops.factor", "Ops.ordered") for "+" > > str(x) # 2 levels, so integer codes of 3 is illegal > ordered[1:2] w/ 2 levels B<C: 2 3 > > > Bill Dunlap > TIBCO Software > wdunlap tibco.com > > On Mon, Mar 30, 2015 at 1:10 PM, Hadley Wickham <h.wickham at gmail.com> > wrote: > >> This is admittedly a contrived example, but... >> >> data(housing, package ="MASS") >> x <- housing$Type + housing$Sat >> match(x, unique(x)) >> >> Hadley >> >> -- >> http://had.co.nz/ >> >> ______________________________________________ >> R-devel at r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-devel >> > >[[alternative HTML version deleted]]
I left out the warning - it's still there. The output object is malformed but either +.factor should prevent this or match() should check. Hadley On Mon, Mar 30, 2015 at 3:50 PM, William Dunlap <wdunlap at tibco.com> wrote:> Did you leave out the warning from "+", which should be an error, > as it produces an illegal ordered factor in this case and factor+factor > is nonsensical? Or is the warning missing in the current development > version of R? > >> x <- factor("A", ordered=FALSE) + factor(c("B","C"), ordered=TRUE) > Warning message: > Incompatible methods ("Ops.factor", "Ops.ordered") for "+" >> str(x) # 2 levels, so integer codes of 3 is illegal > ordered[1:2] w/ 2 levels B<C: 2 3 > > > Bill Dunlap > TIBCO Software > wdunlap tibco.com > > On Mon, Mar 30, 2015 at 1:10 PM, Hadley Wickham <h.wickham at gmail.com> wrote: >> >> This is admittedly a contrived example, but... >> >> data(housing, package ="MASS") >> x <- housing$Type + housing$Sat >> match(x, unique(x)) >> >> Hadley >> >> -- >> http://had.co.nz/ >> >> ______________________________________________ >> R-devel at r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-devel > >-- http://had.co.nz/
Seemingly Similar Threads
- Segfault with match()
- ROBUSTNESS: x || y and x && y to give warning/error if length(x) != 1 or length(y) != 1
- [Q] Get formal arguments of my implemented S4 method
- [Q] Get formal arguments of my implemented S4 method
- Segfault when parsing UTF-8 text with srcrefs