Generating PPC Keywords in R – Part 2

November 4, 2011
By

(This article was first published on Abraham Mathew » R, and kindly contributed to R-bloggers)

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)

To leave a comment for the author, please follow the link and comment on their blog: Abraham Mathew » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Tags: , ,

Comments are closed.

Sponsors

Mango solutions



RStudio homepage



Zero Inflated Models and Generalized Linear Mixed Models with R

Quantide: statistical consulting and training



http://www.eoda.de









ODSC

CRC R books series











Contact us if you wish to help support R-bloggers, and place your banner here.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)