简体   繁体   English

当在两个矩阵上执行时,all.equal 在 R 中做了什么

[英]What does all.equal do in R when it is executed on two matrices

What does all.equal do in R when it is executed on two matrices like bellow?当在如下两个矩阵上执行时,all.equal 在 R 中做了什么? What is Mean relative difference and how is it calculated?什么是平均相对差异,它是如何计算的?

a <-
  matrix(c(4, 1, 1, 4),
         nrow = 2,
         dimnames = list(Guess = c("Milk", "Tea"),
                         Truth = c("Milk", "Tea")))
b <-
matrix(c(2, 3, 3, 2),
       nrow = 2,
       dimnames = list(Guess = c("Milk", "Tea"),
                       Truth = c("Milk", "Tea")))

all.equal(a, b)

For numeric input mean relative difference is calculated as absolute difference between both vectors as compared to first vector.对于数字输入,平均相对差被计算为两个向量与第一个向量相比的绝对差。 So something like所以像

mean(abs(a-b))/mean(abs(a))
#[1] 0.8

This is a weird behavior.这是一种奇怪的行为。 "Istruing" all equal would produce expected output (FALSE). "Istring" all equal 将产生预期的 output (FALSE)。 Sorry if I'm not really answering the question.对不起,如果我没有真正回答这个问题。

a <-
  matrix(c(4, 1, 1, 4),
         nrow = 2,
         dimnames = list(Guess = c("Milk", "Tea"),
                         Truth = c("Milk", "Tea")))
b <-
  matrix(c(2, 3, 3, 2),
         nrow = 2,
         dimnames = list(Guess = c("Milk", "Tea"),
                         Truth = c("Milk", "Tea")))

isTRUE(all.equal(a, b))

a <-
  matrix(c(4, 1, 1, 4),
         nrow = 2,
         dimnames = list(Guess = c("Milk", "Tea"),
                         Truth = c("Milk", "Tea")))
b <-
  matrix(c(4, 1, 1, 4),
         nrow = 2,
         dimnames = list(Guess = c("Milk", "Tea"),
                         Truth = c("Milk", "Tea")))

isTRUE(all.equal(a, b))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM