Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"invalid argument type" error with all.equal. R

Tags:

r

all.equal() gives an "invalid argument type" error with these data. Any idea?

>matrix1
  1 2   3 4   5
1 0 0 0.0 0 0.0
2 1 0 0.0 0 0.0
3 0 1 0.0 0 0.0
4 0 0 0.5 0 0.5
5 0 0 1.0 0 0.0
>rowSums(matrix1)
1 2 3 4 5 
0 1 1 1 1 
> !all.equal(as.vector(rowSums(matrix1)), as.vector(rep(1, nrow(matrix1))), check.attributes=FALSE)
Error in !all.equal(as.vector(rowSums(matrix1)), as.vector(rep(1,  : 
  invalid argument type
like image 336
imriss Avatar asked Aug 02 '13 20:08

imriss


1 Answers

all.equal is not returning that error, ! is:

> !""
Error in !"" : invalid argument type

This is because all.equal does not return a logical value when the two objects aren't roughly equal. This is documented in the first paragraph of ?all.equal, where it suggests you use isTRUE(all.equal(...)).

like image 59
Joshua Ulrich Avatar answered Oct 15 '22 02:10

Joshua Ulrich