Entering edit mode
Patrick Schorderet
▴
10
@patrick-schorderet-6146
Last seen 11.2 years ago
Dear All,
I'm trying to compare two tables in R and find the differences between
them (what has the user changed). The approach is the following:
- Import .xls table into matrices
- compare matrixes (and highlight differences)
- output the 'new' table, with highlighted differences
I can do all of this in R pretty easily, but the people I'm working
with need a .xls file in return, with the highlighted changes (for
example fill the cells which have changed with a color, or make them
bold, etc).
Any ideas?? Thanks for the help,
Patrick
PS: Here's the small script I have wrote so far. Ideally, M should
carry some metadata around highlighting the differences I have
applied.
library(compare)
library(gdata)
# Load .xls file
LoadXLSXFile <- function(file_name){
X <- as.matrix(read.xls(paste("./Desktop/", file_name,
sep="")))
return(X)
}
# Two matrices A and B of equal size
A<-LoadXLSXFile("A.xlsx")
B<-LoadXLSXFile("B.xlsx")
M <- A
booT <- which((A==B)==TRUE)
M[booT] <- ""
write.table(M, "./Desktop/ComparedOutput.xls", sep="\t", col.names =
F, row.names = F)
