John Smith
John Smith

Reputation: 2886

R using apply for string comparisons

Im trying to use apply to compare the distance between a grid of text The idea would be to try and then parallelize the operation using the parallel function in R

When i run the below code i get the error

Error in FUN(newX[, i], ...) : unused argument (newX[, i])

Can anyone see where I'm going wrong?

d <- iris
my_grid <- expand.grid(unique(d$Species), unique(d$Species), stringsAsFactors = FALSE)
apply(my_grid, MARGIN =  1, FUN = levenshteinSim, str1 = Var1, str2 = Var2)

Upvotes: 0

Views: 52

Answers (1)

platypus
platypus

Reputation: 516

I think the function in apply is not properly defined, can you try this

apply(my_grid, MARGIN =  1, FUN = function(V) levenshteinSim(V[1],V[2]))

Upvotes: 1

Related Questions