3

I have two data sets as follows df1 and df2. I want to merge both into one df by matching df1$pkg and df2$name. But the strings in df1$pkg and df2$name are not exactly same. I tried using agrep but that did not work. Will appreciate any help.

x<-agrep(df1[,2], df2[,1],ignore.case=T, value=T)
Warning message:
In agrep(df1[, 2], df2[, 1], ignore.case = T, value = T) :
  argument 'pattern' has length > 1 and only the first element will be used
> x
character(0)



df1<<-data.frame(apname=c("photo eff pro", "olx", "firefox", "word search", "chrome","bbc news"), 
             pkg=c("bbc.mobile.news", "com.dhqsolutions", "#com.olx.olx","org.mozilla.firefox","ws.letras", "com.chrome"),
             apcat=c(5,3,4,5,4,1))
df2<-data.frame(name=c("bbc.mob.news.ww", "com.dhqsolutions.enjoyphoto", "com.olx.olx","org.mozilla.firefox","ws.letras","chrome.approximated"),
            tic=c(10000, 12345, 123456, 23456,9903, 12389034))
user24318
  • 485
  • 5
  • 22

1 Answers1

0

You're going to want to use one of the apply family of functions (see this excellent Q&A) or some type of loop. That's why you receive the warning message. Consider this simple example:

vec1 <- c("Dog", "Cat", "Pony")
vec2 <- c("catty", "doggy", "fish", "ponyt")
sapply(vec1, agrep, vec2)
# Dog  Cat  Pony 
#   2    1     4 

In your case, you will likely want to do something like: sapply(df1$pkg, agrep, df2$name)

Community
  • 1
  • 1
JasonAizkalns
  • 20,243
  • 8
  • 57
  • 116