Dear R-user,

I'm trying to compare two sets of results and wanted to find out which
element in the two data frame/matrix are different.

I wrote the following function and it works ok, and gives me a long list of
"good" as outcomes.


CHECK<-
function (x = "file1", y = "file2")
{
    for (i in 1:nrow(x)) {
        for (j in 1:ncol(x)) {
            if (x[i, j] == y[i, j]) {
                print("good")
            }
            else {
                print("check")
            }
        }
    }
}


However, as the two datasets I was comparing are large (400*100 roughly),
so I would like to create a matrix to identify which ones are not same in
the two dataframes.

So I added 'CHECK_XY' in my code but  when I run it, I got 'Error in
CHECK_XY[i, j] = c("good") : subscript out of bounds'.

Could anyone help please??

CHECK_1<-
function (x = "file1", y = "file2")
{
    NROW <- nrow(x)
    NCOL <- ncol(x)
    CHECK_XY <- as.matrix(NA, NROW, NCOL)
    for (i in 1:nrow(x)) {
        for (j in 1:ncol(x)) {
            if (x[i, j] == y[i, j]) {
                CHECK_XY[i, j] = c("good")
            }
            else {
                CHECK_XY[i, j] = c("check")
            }
        }
    }
    print(CHECK_XY)
}

Thanks!
HJ

	[[alternative HTML version deleted]]

