[R] Saving Mean Relative Difference from all.equal()

David Winsemius dwinsemius at comcast.net
Fri Feb 27 06:26:40 CET 2015


> On Feb 26, 2015, at 2:02 PM, Scott Colwell <scolwell at uoguelph.ca> wrote:
> 
> I think I have one solution. Not very pretty though. Relies on the text not
> changing at all.
> 
> as.numeric(gsub("Mean relative difference: ", "",
> all.equal(cov2cor(ITEMCOV),cor(item.data))[2]))
> 
> Is there a better way?
> 

`all.equal` is a generic function and it appears you are interested in `all.equal.numeric`. Not sure if it’s “better” but you could fairly easily hack the all.equal.numeric function to replace this code (near the end of the function code) :

if (is.na(xy) || xy > tolerance) 
        msg <- c(msg, paste("Mean", what, "difference:", format(xy)))

,,, with:

if (is.na(xy) || xy > tolerance) 
        msg <-  xy

(probably best to make it have a different name and not use 'all.equal' to name it.)

When it did that I got this as a result:

> all.EQ( seq(1,2, by=0.1)*10, 10:20)
[1] TRUE
> all.EQ( seq(1,2, by=0.11)*10, 10:20)
[1] "Numeric: lengths (10, 11) differ"
> all.EQ(seq(1,2, by=0.11)*10, 10:19)
[1] 0.03225806

— 


David Winsemius, MD
Alameda, CA, USA



More information about the R-help mailing list