I have a series of strings and I am trying to find all combinations and then
assign 1 or 0 to them based
on whether they contain the words car or budged. I want the data to look
like:


car          budget

 cheap car insurance quote        1        0
   budget car insurance quote     1        1
   cheap auto insurance quote     0        0
  budget auto insurance quote     0        1
   cheap car insurance quotes     1        0
  budget car insurance quotes     1        0
  cheap auto insurance quotes     0        0
 budget auto insurance quotes     0        1

I've created all the possible values using the following commands,
but I wanted to know if I could automate the process whereby it would
create the string combinations and assign binary values appropriately.


roots <- c("car insurance", "auto insurance")
prefix <- c("cheap", "budget")
suffix <- c("quote", "quotes")

d <- do.call(paste, expand.grid(prefix, roots, suffix))
df = data.frame(keyword=c(d))
df


I realize that this process can be done in two separate stages with the
stringr package,
but I'm trying to just get the thing done in one.

Do I need to combine both the functions from above and the stringr package
inside
a function? Help!

I'm using R 2.13 on Ubuntu 10.10


Abraham
WebRep
Overall rating

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to