title: R function to input character vector
body: <p>I currently have 10 vectors that look like the following:</p>
  
  <pre><code>string1 &lt;- c("house", "home", "cabin")
  string2 &lt;-c("hotel", "hostel", "motel")
  </code></pre>
  
  <p>and so on for 10 strings.</p>
  
  <p>R newbie learning functions. I have the following code I want to execute across these 10 strings, and turn in to a function. This code takes in these strings and searches for matches and creates a new variable:</p>
  
  <pre><code>a$string.i &lt;- (1:nrow(a) %in% c(sapply(string1, grep, a$Contents, fixed = TRUE))) +0
  </code></pre>
  
  <p>As I am new to R, I'm stumped on how to turn this into a function. Do I need to first define the number of strings, then set 'string1' in the above code to x? How do I set the name of the variable = to the name of the string?</p>
  
  <p>Some sample data:</p>
  
  <pre><code>a &lt;- read.table(text='Contents     other
  1     "a house a home"     "111"
  2     "cabin in the woods"     "121"', header=TRUE)
  </code></pre>