dimanche 3 février 2019

If statement doesn't work with a matrix condition

I have absolutely no idea why this is happening. My if statement doesn't work with a condition involving matrices.

This is my input:

i = matrix(c(1,0,0,1),nrow=2,ncol=2,byrow=TRUE)
j = matrix(c(1,0,0,2),nrow=2,ncol=2,byrow=TRUE)
if(i%*%i == j){
  print("yes")
}

This is my output:

> i = matrix(c(1,0,0,1),nrow=2,ncol=2,byrow=TRUE)
> j = matrix(c(1,0,0,2),nrow=2,ncol=2,byrow=TRUE)
> if(i%*%i == j){
+   print("yes")
+ }
[1] "yes"
Warning message:
In if (i %*% i == j) { :
  the condition has length > 1 and only the first element will be used

Aucun commentaire:

Enregistrer un commentaire