I have a repetative task in R and i'm trying to find a more efficient way to
perform
the following task.


lst <- list(roots = c("car insurance", "auto insurance"),
             roots2 = c("insurance"), prefix = c("cheap", "budget"),
             prefix2 = c("low cost"), suffix = c("quote", "quotes"),
             suffix2 = c("rate", "rates"), suffix3 = c("comparison"),
             state = c(state), inscompany = c(inscompany), city=c(city),
             cityst = c(cityst), agency=c(agency))


myone <- function(x, y) {
          m1 <- do.call(paste, expand.grid(lst[[x]], lst[[y]]))
          mydf <- data.frame(keyword=c(m1))
      }
      mytwo <- function(x, y, z){
          m2 <- do.call(paste, expand.grid(lst[[x]], lst[[y]], lst[[z]]))
          mydf2 <- data.frame(keyword=c(m2))
      }
      d1 = mytwo("prefix", "roots", "suffix")
      d2 = mytwo("prefix", "roots", "suffix2")
      d3 = mytwo("prefix", "roots", "suffix3")
      d4 = mytwo("prefix2", "roots", "suffix")
      d5 = mytwo("prefix2", "roots", "suffix2")
      d6 = mytwo("prefix2", "roots", "suffix3")
      d7 = mytwo("prefix", "roots2", "suffix")
      d8 = mytwo("prefix", "roots2", "suffix2")
      d9 = mytwo("prefix", "roots2", "suffix3")
      d10 = mytwo("prefix2", "roots2", "suffix")
      d11 = mytwo("prefix2", "roots2", "suffix2")
      d12 = mytwo("prefix2", "roots2", "suffix3")
      d13 = myone("prefix", "roots")
      d14 = myone("prefix2", "roots")
      d15 = myone("prefix", "roots2")
      d16 = myone("prefix2", "roots2")
      d17 = myone("roots", "suffix")
      d18 = myone("roots", "suffix2")
      d19 = myone("roots", "suffix3")
      d20 = myone("roots2", "suffix")
      d21 = myone("roots2", "suffix2")
      d22 = myone("roots2", "suffix3")
      d23 = myone("state", "roots")
      d24 = myone("city", "roots")
      d25 = myone("cityst", "roots")
      d26 = myone("inscompany", "roots")
      d27 = myone("state", "roots2")
      d28 = myone("city", "roots2")
      d29 = myone("cityst", "roots2")
      d30 = myone("inscompany", "roots2")
      d31 = mytwo("state", "roots", "suffix")
      d32 = mytwo("city", "roots", "suffix")
      d33 = mytwo("cityst", "roots", "suffix")
      d34 = mytwo("inscompany", "roots", "suffix")
      d35 = mytwo("state", "roots", "suffix2")
      d36 = mytwo("city", "roots", "suffix2")
      d37 = mytwo("cityst", "roots", "suffix2")
      d38 = mytwo("inscompany", "roots", "suffix2")
      d39 = mytwo("state", "roots", "suffix3")
      d40 = mytwo("city", "roots", "suffix3")
      d41 = mytwo("cityst", "roots", "suffix3")
      d42 = mytwo("inscompany", "roots", "suffix3")
      d43 = mytwo("state", "roots2", "suffix")
      d44 = mytwo("city", "roots2", "suffix")
      d45 = mytwo("cityst", "roots2", "suffix")
      d46 = mytwo("inscompany", "roots2", "suffix")
      d47 = mytwo("state", "roots2", "suffix2")
      d48 = mytwo("city", "roots2", "suffix2")
      d49 = mytwo("cityst", "roots2", "suffix2")
      d50 = mytwo("inscompany", "roots2", "suffix2")
      d51 = mytwo("state", "roots2", "suffix3")
      d52 = mytwo("city", "roots2", "suffix3")
      d53 = mytwo("cityst", "roots2", "suffix3")
      d54 = mytwo("inscompany", "roots2", "suffix3")
      d55 = mytwo("prefix", "state", "roots")
      d56 = mytwo("prefix", "city", "roots")
      d57 = mytwo("prefix", "cityst", "roots")
      d58 = mytwo("prefix", "inscompany", "roots")
      d59 = mytwo("prefix2", "state", "roots")
      d60 = mytwo("prefix2", "city", "roots")
      d61 = mytwo("prefix2", "cityst", "roots")
      d62 = mytwo("prefix2", "inscompany", "roots")
      d63 = mytwo("prefix", "state", "roots2")
      d64 = mytwo("prefix", "city", "roots2")
      d65 = mytwo("prefix", "cityst", "roots2")
      d66 = mytwo("prefix", "inscompany", "roots2")
      d67 = mytwo("prefix2", "state", "roots2")
      d68 = mytwo("prefix2", "city", "roots2")
      d69 = mytwo("prefix2", "cityst", "roots2")
      d70 = mytwo("prefix2", "inscompany", "roots2")
      d71 = mytwo("prefix", "inscompany", "suffix")
      d72 = mytwo("prefix", "inscompany", "suffix2")
      d73 = mytwo("prefix", "inscompany", "suffix3")
      d74 = mytwo("prefix2", "inscompany", "suffix")
      d75 = mytwo("prefix2", "inscompany", "suffix2")
      d76 = mytwo("prefix2", "inscompany", "suffix3")

Obviously, this code gets rather repetative, even with the function, and I
was
wondering if there's a shortcut that I should consider to simplify the
process.

Thanks,

I'm running R 2.13 on Ubuntu 10.10

	[[alternative HTML version deleted]]

