title: Adding a new column to one dataframe using a column from a second consisting of vectors with strings in R
body: <p>I'm trying to add a new column to a dataframe, the data will be filled from column A in second dataframe and depend on column B. The values in Column B are vectors. The length of vectors in my real data are far too long for an if_else statement, I'm looking for something more along the lines of stringer or grepl recognizing character strings but cycling through the rows of the dataframe like a for loop.</p>
  <pre><code>df1 &lt;- data.frame(col1 = c('siteA', 'siteB', 'siteC', 'siteD'),
                    col2 = c('ecoA', 'ecoB', 'ecoC', 'ecoD'))
  
  df2 &lt;- data.frame(colA = c('type1', 'type2'),
                    colB = c(&quot;c('ecoA','ecoC')&quot;, &quot;c('ecoB','ecoD')&quot;))
  </code></pre>
  <p>I've tried merge, mutate with if statements, joins (dplyr), and case when, but again these either didn't fill all of the rows or they're far too long/complicated for the data set I have.</p>
  <p>This is the end result I'm hoping for:</p>
  <pre><code>|col1 | col2 |colA |
  |-----|------|-----|
  |siteA| ecoA |type1|
  |siteB| ecoB |type2|
  |siteC| ecoC |type1|
  |siteD| ecoD |type2|
  </code></pre>