0

I have a dataset which has search words and other attributes like title, short description and product description. I want to loopup "Search" words in multiple columns and want to get results as "Tru or False" for each and every column

With the great solution mentioned on this page "How to find that a word/words in a column is present in another column consisting a sentence", I figured out the way to get results for one column,but since I am very new to R(And coding), I am unable to figure out how to get the results on multiple columns without writing the same code again and again for every column.

df<-data.frame(search, short_description, product_description)

df[, "lookup"] <- gsub(" ", "|", df[,("search")])
df[,"t"] <- mapply(grepl, df[,"lookup"], df[, "short_description"])

search values:

row1: aps mobile electronics specialty-aps electronics-intl-ship warehouse-deals
row2: maschine phone gadgets iphone

Short description

row1: mobile is good


row2: everyone uses iphone

product_description

row1: (blank)



row2: mobiles are required

"structure(list(search = structure(1:2, .Label = c("aps mobile electronics specialty-aps electronics-intl-ship warehouse-deals", "maschine phone gadgets iphone"), class = "factor"), short_description = structure(2:1, .Label = c("everyone use iphone", "mobile is good"), class = "factor"), product_description = structure(1:2, .Label = c("", "mobiles are required"), class = "factor"), lookup = c("aps|mobile|electronics|specialty-aps|electronics-intl-ship|warehouse-deals", "maschine|phone|gadgets|iphone"), t = c(TRUE, TRUE)), row.names = 1:2, class = "data.frame")"

Expected Output "t1" for every attribute: search keyword and output

1) I want to get the "t" column to show the search results for every column. (and not the combined result).

Can I simply select the column numbers in my code and get this data?

Opak
  • 1
  • 1
  • 1
  • 3
    Welcome to SO. Please post your data in a reproducible format using `dput(head(YOUR_DATA))` and posting the results. Also, post an example of what you want your end product to look like. – Ben G Apr 17 '19 at 13:21
  • Thanks Ben, Have edited it! – Opak Apr 18 '19 at 08:31
  • Hi @BenG will it be possible for you to help with the solution? – Opak Apr 20 '19 at 06:54

0 Answers0