I have a for loop that compares 2 addresses column to make the third column.
i am having a hard time converting this for loop to apply function that takes arguments too.
code that works:
for (i in 1:length(df_name_address$col1)){
print(i)
df_test$flag[i] <- SequenceMatcher$new(tolower(df_test$address[i]),tolower(df_test$address2[i]))$ratio()
}
NOTE: sequenceMatcher is just a function in fuzzywuzzyR so dont need to worry about it i just want to convert this to apply or something in the same family as the efficiency is really low for for loop and big datasets
sample:
col1 address address2 flag
1 abced abcd ad 0
2 def def 1
3 abcdef abcdef 1
4 xqc abc 0
function tried::
seqM2 <- function(x,table,flag,one,two) {
for (i in 1:length(table$one)){ return(SequenceMatcher$new(tolower(table$one[i]),tolower(table$two[i]))$ratio())
}
}
where
table = Data frame
flag = new column
one = address column
two = address column 2
how do I pass this to mapply?