I have a data.frame with two rows and 20 columns where each column holds one character, which roughly looks like this (columns scrunched here for clarity):
Cols 1-20
row1 ghuytuthjilujshdftgu
row2 ghuytuthjilujshdftgu
I want a mechanism for comparing these two strings character by character (column by column) starting from position 10 and scanning outwards, returning the number of matching characters until the first difference is encountered. In this case it is obvious that both lines are identical so the answer would be 20. The important thing would be that even if they are completely identical, as in the case above, there should not be an error message (it should be returned).
With this alternate example, the answer should be 12:
Cols 1-20
row1 ghuytuthjilujshdftgu
row2 XXXXXXXXjilujshdftgu
Here is some code to generate the data frames:
r1 <- "ghuytuthjilujshdftgu"
r2 <- "ghuytuthjilujshdftgu"
df1 <- as.data.frame(rbind(unlist(strsplit(r1, "")), unlist(strsplit(r1, ""))))
r1 <- "ghuytuthjilujshdftgu"
r2 <- "XXXXXXXXjilujshdftgu"
df1 <- as.data.frame(rbind(unlist(strsplit(r1, "")), unlist(strsplit(r1, ""))))
Edit.
the class of the object is data.frame and it is subsettable- with dim = 2,20 (each column / character is accessible on its own)