I have a data frame and want to know if a a certain string is present.
I want to know if any of the values in df[,1] contain anything from inscompany.
df = data.frame(company=c("KMart", "Shelter"), var2=c(5,7))
if( df[,1] == inscompany ) print("YES")
inscompany <- c("21st Century Auto Insurance", "AAA Auto Insurance", "AARP Auto Insurance",
"Allstate Auto Insurance", "American Family Auto Insurance", "Eastwood Auto Insurance",
"Erie Auto Insurance", "Farmers Auto Insurance", "GMAC Auto Insurance", "Hartford Auto Insurance",
"Infinity Auto Insurance", "Mercury Auto Insurance", "Nationwide Auto Insurance", "Progressive Auto Insurance",
"Shelter Insurance Company", "Titan Auto Insurance", "Travelers Auto Insurance", "USAA Auto Insurance")
I get an error message that it can only check the first value of inscompany to df[,1].
Help!
You want
%in%. Here is an exampe:The
match()function is related, see the help page for details.