-2

I have the following code, but i get the message;

argument 'pattern' has length > 1 and only the first element will be used.

how do i write a function so that test_master_raw2$match_work will be applied to each row of the data frame?

test_master_raw2$match_work <- agrep(test_master_raw2$file_name4,meta2$file_name4, ignore.case = TRUE,value = TRUE,max.distance = .01)
Edo
  • 7,567
  • 2
  • 9
  • 19
joshbh
  • 13
  • 1
  • you should provide a reproducible example. drop your data in the question. `dput(test_master_raw2)` – Edo Aug 20 '20 at 21:38
  • 1
    Questions on SO (especially in R) do much better if they are reproducible and self-contained. By that I mean including attempted code (please be explicit about non-base packages), sample representative data (perhaps via `dput(head(x))` or building data programmatically (e.g., `data.frame(...)`), possibly stochastically after `set.seed(1)`), perhaps actual output (with verbatim errors/warnings) versus intended output. Refs: https://stackoverflow.com/q/5963269, [mcve], and https://stackoverflow.com/tags/r/info. – r2evans Aug 20 '20 at 21:40

1 Answers1

0

You could try with this. I made up a df for the sake of the example.

df <- data.frame(x = c("hello", "halo"),
                 y = c("helo", "ahlu"))

apply(df, 1, function(x) agrep(x[1], x[2], ignore.case = TRUE, value = TRUE, max.distance = .01))

Edo
  • 7,567
  • 2
  • 9
  • 19