In a previous post, I discussed how to generate PPC keywords in R. In this post I will provide another example of how to perform this task. Let’s say that I am a auto insurance company that only operates in the state of Illinois. I’m planing on bidding on keywords in Bing and Google which have the name of each city in Illinois followed by ‘auto insurance.’ Using just the sprintf function and a data structure with the Illinois cities, I can generate the desired keywords using the following code. Some of you are probably wondering why an advertiser would bid on keywords that contain each city in Illinois. Well, there are very few instances in which it would make sense to actually bid on keywords that contain city names or zip codes. Just because you can, doesn’t mean you should.
DF <- read.csv("http://www.census.gov/tiger/tms/gazetteer/zips.txt", header = FALSE) str(DF) head(DF)
DF[ ,c(1,5,6,7,8)] <- NA head(DF) df <- DF[,colSums(is.na(DF))<nrow(DF)] #removes all NA values names(df) <- c("zip", "state", "city") head(df) il = subset(df, state=="IL") ilcity = unique(tolower(il$city)) ilcity = as.character(ilcity) ilcity = gsub("(^|[[:space:]])([[:alpha:]])", "\\1\\U\\2", ilcity, perl=TRUE) ilcity dt = c("%s auto insurance") dat = sprintf(dt, ilcity)