Hello, Does anyone know how to save the numeric value of the "mean relative difference" when using the all.equal() command? For example this: all.equal(cov2cor(ITEMCOV),cor(item.data)) Gives: [1] "Attributes: < Length mismatch: comparison on first 1 components >" [2] "Mean relative difference: 0.01523708" I'd like to save the value 0.01523708 in a numeric format. Thanks, -- View this message in context: http://r.789695.n4.nabble.com/Saving-Mean-Relative-Difference-from-all-equal-tp4703905.html Sent from the R help mailing list archive at Nabble.com.
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? -- View this message in context: http://r.789695.n4.nabble.com/Saving-Mean-Relative-Difference-from-all-equal-tp4703905p4703908.html Sent from the R help mailing list archive at Nabble.com.
David Winsemius
2015-Feb-27 05:26 UTC
[R] Saving Mean Relative Difference from all.equal()
> 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