I want to save a numerical matrix and then restore it accurately. But if I use identical() to compare the before- and after-saved matrices, they are not identical. I guess the problem is caused by floating point precision issues. How can I make the two matrices identical?
Thanks!
options(digits = 10)
data <-
c(1 / 11, 1 / 22, 1 / 33, 1 / 44, 1 / 55, 1 / 66, 1 / 77, 1 / 88, 1 / 99) # Generate a numerical matrix.
x <- matrix(data,
nrow = 3,
ncol = 3,
byrow = TRUE)
write.table(x, "test.csv") # Save the matrix.
y <- as.matrix(read.table("test.csv")) # Restore the matrix.
y <- unname(y) # Remove the attributes.
all.equal(x, y) # I got TRUE.
identical(x, y) # I got FALSE. How can I get TRUE here?
unlink("test.csv")