Use agrep to return a different variable

192 views Asked by At

I'm doing a lookup from one table to another using agrep, but the results I want to return are not the values being matched. They're from another column/variable. My current agrep syntax:

personalfolders$DOBMatch <- lapply(personalfolders$DOB, agrep, allees2$`Date Of Birth`, max.distance=1)

So now: personalfolders$DOBMatch == c(290, 312) but what I want is to return the values from another variable in the data frame I'm looking up called: allees2$PartPathmatch1 for each of those returned rows. I know about the value=TRUE variable for agrep, but I believe that only returns the lookup value itself.

Is there a way I can either use the personalfolders$DOBMatch field that now contains something like c(290, 312) to create another vector then add it to the frame with the lookup results, or can I add another argument to the agrep function to return the allees2$PartpathMatch1 matched values directly?

1

There are 1 answers

0
Christoph Wolk On BEST ANSWER

How about

personalfolders$DOBMatch <- lapply(personalfolders$DOB, function(y) allees2$PartPathMatch1[agrep(y, allees2$`Date Of Birth`, max.distance=1)])