You're not outputting correctly. Run this version and see the comparisons happening in place. Comment out the message()
once you are satisfied that everything is working correctly.
library(RecordLinkage)
df <- structure(c("1", "1", "2", "2", "3", "4", "4", "4", "5", "6",
"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "string1",
"str2ing", "3string", "string6", "s7ring", "string8", "string9",
"string10", "string1", "str2ing"), .Dim = c(10L, 3L), .Dimnames = list(
NULL, c("doc_id", "text_id", "text")))
result <- matrix(ncol = 10, nrow = 10)
# nrow() and ncol() are more elegant ways of getting row/column counts.
for(j in 1:nrow(df)) {
for(i in 1:nrow(df)) {
message(sprintf("comparing i=%s (%s), j=%s (%s)\n", j, df[i, 1], i, df[j, 1]))
if(identical(df[i, 1], df[j, 1])) {
result[i, j] <- levenshteinDist(df[j, 3], df[i, 3])
} else {
result[i, j] <- "Not Compared"
}
# printing inside the inner for loop
print(result[i, j])
}
}