In R, how can one check if two lists are equal, up to a permutation?
For example,
l1 <- list(diag(3), diag(c(-1,-1,1)))
l2 <- list(diag(c(-1,-1,1)), diag(3))
I would like l1 and l2 to be considered equal.
At present, what I have is
library(purrr)
map_lgl(l1, function(x) any(map_lgl(l2, function(y) identical(x,y))))
It works for this example, but it is not very elegant.
What could be a better way to achieve this?