title: How to do rowwise matching in data.table between list-column and external vector?
body: <p>I'm trying to do a rowwise matching for vector elements nested inside a <code>data.table</code> list-column.</p>
  <pre class="lang-r prettyprint-override"><code>library(tibble)
  library(data.table)
  
  my_dt &lt;-
    tibble::tribble(
      ~col_x,   ~col_y,
      &quot;a&quot;,      c(1, 2, 3),
      &quot;b&quot;,      c(4, 5, 6),
      &quot;c&quot;,      c(7, 8, 9)
    ) %&gt;%
    as.data.table()
  
  external_vec &lt;- 1:9
  </code></pre>
  <p>I want to match each element from <code>col_y</code> against <code>external_vec</code> such that I will get a new column in <code>my_dt</code> that is equivalent to <code>external_vec %in% col_y</code>, such as:</p>
  <pre class="lang-r prettyprint-override"><code># desired output
  ##    col_x col_y                                 new_col
  ## 1:     a 1,2,3  TRUE, TRUE, TRUE,FALSE,FALSE,FALSE,...
  ## 2:     b 4,5,6 FALSE,FALSE,FALSE, TRUE, TRUE, TRUE,...
  ## 3:     c 7,8,9 FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,...
  </code></pre>
  <hr />
  <p><strong>EDIT</strong></p>
  <hr />
  <p>I know how to implement a solution based on tidyverse's <code>purrr</code>, like the following. However, I'm looking for a <code>data.table</code> native functionality.</p>
  <pre class="lang-r prettyprint-override"><code># this works but relies on purrr and dplyr, which I hope to avoid in this problem
  my_dt %&gt;%
    tibble::add_column(ext_vec_as_col = list(external_vec)) %&gt;%
    mutate(new_col = purrr::map2(.x = ext_vec_as_col, .y = col_y, .f = ~.x %in% .y) )
  #&gt;    col_x col_y  ext_vec_as_col                                 new_col
  #&gt; 1:     a 1,2,3 1,2,3,4,5,6,...  TRUE, TRUE, TRUE,FALSE,FALSE,FALSE,...
  #&gt; 2:     b 4,5,6 1,2,3,4,5,6,... FALSE,FALSE,FALSE, TRUE, TRUE, TRUE,...
  #&gt; 3:     c 7,8,9 1,2,3,4,5,6,... FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,...
  </code></pre>