1

I have a dataframe

Name
1.Started
2.Home
3.Signout

I want to compare with another column in another dataframe

Df
1.help/services/Home 
2./msoffice/home 
3./windows.support

Expected output:

False
True
False

This shows Home from name exists in df. It's matching partially with another entire column.

Rui Barradas
  • 70,273
  • 8
  • 34
  • 66
maddie
  • 13
  • 2
  • `sapply(Name[[1]], function(x) grepl(x, Df[[1]], ignore.case = TRUE))`. – Rui Barradas Mar 23 '20 at 06:04
  • Does this answer your question? [dplyr: inner\_join with a partial string match](https://stackoverflow.com/questions/32914357/dplyr-inner-join-with-a-partial-string-match) – MarkusN Mar 23 '20 at 06:44

2 Answers2

0

We can compare Name from df1 and use basename to get last part of the string.

df1$Name %in% basename(df2$col)
#[1] FALSE  TRUE FALSE

data

Assuming the dataframes are df1 and df2 as below.

df1 <- structure(list(Name = c("Started", "Home", "Signout")), row.names = c(NA, 
      -3L), class = "data.frame")

df2 <- structure(list(col = c("help/services/Home", "/msoffice/home", 
"/windows.support")), class = "data.frame", row.names = c(NA, -3L))
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
0

We can use grepl

mapply(grepl, tolower(df1$Name), tolower(df2$col))
#FALSE    TRUE   FALSE 

data

df1 <- structure(list(Name = c("Started", "Home", "Signout")), row.names = c(NA, 
      -3L), class = "data.frame")

df2 <- structure(list(col = c("help/services/Home", "/msoffice/home", 
"/windows.support")), class = "data.frame", row.names = c(NA, -3L))
akrun
  • 874,273
  • 37
  • 540
  • 662