I am here new. I used this forum a lot for questions, most of the time i can solve my problems them with other questions but not this time. I have two dataframes with cells, one dataframe (df1) with newsarticles and one (df2) with company names.
df1$articles: news articles in every cell, one column whole text,
df1$tags: only the tags of the article
df2$names: company names
i want to see whether those company names occur in the news articles dataset and if yes that it could give a TRUE/FALSE or 0/1 variable.
I tried: identical (df1$tags,df2$names) but it gives a FALSE indication, but it should give TRUE for some values.
I also tried a fore-loop for this:
for(i in 1:length(df1$tags))
{
#for(j in 1:length(df2$names))
#{
if(identical(df1$tags$tags[i],df2$names[j]))
{
print("i found something")
}
}
}
So someone that could help me out? much appreciated!
Example:
df1$article: body of the article e.g. Nederlanders kunnen weer vanaf 1 maart tot 1 mei aan.....
df1$tags: tags of the article e.g. Philips
df2$names: here i have Philips as one of the company names
See whether those company names in df2$names occur in df1$articles or df1$tags
Final Dput example data
structure(list(id = 1:2, body = structure(1:2, .Label = c("Dinsdag werd bekend dat de Euroland door de",
"Ieder jaar verandert er wel iets in de belastingaangifte"), class = "factor"),
tags = structure(1:2, .Label = c("Belastingaangifte", "Euroland"
), class = "factor")), .Names = c("id", "body", "tags"), row.names = c(NA,
-2L), class = "data.frame")
structure(list(id = 1:2, names = structure(c(1L, 1L), .Label = "Belastingaangifte", class = "factor"),
names1 = structure(c(1L, 1L), class = "factor", .Label = "Belastingaangifte")), .Names = c("id",
"names", "names1"), row.names = c(NA, -2L), class = "data.frame")