title: How do you apply a function to each cell of a column?
body: <p>I am using the following perfectly working function to parse through text data to find the percentage stenosis of arteries in patient medical records.</p>
  <pre><code>txt &lt;- &quot;Small caliber RCA with 50% proximal and 70% mid stenoses.&quot;
  
  coronary_anatomy &lt;- function(x) {
      
      # Check if sentence
      if(!is.character(x)) {stop(&quot;Requires character string&quot;, call. = FALSE)}
      
      # Establish variables
      epicardial &lt;- c(&quot;LM&quot;, &quot;LAD&quot;, &quot;LCX&quot;, &quot;RCA&quot;)
      mods &lt;- c(&quot;proximal&quot;, &quot;mid&quot;, &quot;distal&quot;, &quot;ostial&quot;)
      
      sentence &lt;-
          tibble(line = 1, sentence = x) %&gt;%
          tidytext::unnest_tokens(input = sentence, output = word, to_lower = FALSE) %&gt;%
          pull(word)
      
      # Identify number/locations of disease
      artery &lt;- sentence[which(sentence %in% epicardial)]
      locs &lt;- grep(&quot;\\d+&quot;, sentence) 
      mlocs &lt;- which(sentence %in% mods)
      
      # Find the nearest neighbors to identify which modifier goes with which location
      space &lt;- combn(mlocs, length(locs))
      dist &lt;- apply(space, 2, function(x) {sum(abs(locs - x))})
      matched &lt;- space[, which.min(dist)]
      
      tbl &lt;- 
          tibble(
              anatomy = paste(sentence[matched], artery),
              stenosis = as.numeric(sentence[locs])
          )
      
      # Return
      return(tbl)
  }
  
  # Test it out
  
  coronary_anatomy(txt)
  
  Output:
  
  # A tibble: 2 x 2
  anatomy      stenosis
  &lt;chr&gt;           &lt;dbl&gt;
  1 proximal RCA       50
  2 mid RCA            70
  </code></pre>
  <p>The code works great. But now I am running into issues applying it on a larger scale. I want to apply this code to a data frame with a whole column of patient medical records. A simplified data frame of the data frame I want to run the function through is shown below.</p>
  <pre><code># A tibble: 2 x 2
  PatientID      Records
  &lt;chr&gt;           &lt;chr&gt;
  1 1234            Small caliber RCA with 50% proximal and 70% mid stenoses
  2 1235            Small caliber LCX with 40% proximal and 70% mid stenoses
  </code></pre>
  <p>So now comes the issue. I want to somehow run this function through the entire records column. However, running this function(as shown above) outputs a tibble that will vary in size depending on how how much info is available to parse.</p>
  <p>Does anyone smarter than me have any idea how to run this function through each cell in a column of a data table containing medical records, and output it in an organized manner, given that the output is a tibble?</p>