title: Dataframe to dictionary like nested list in R
body: <p>I am trying to create a nested dictionary starting from a data.frame.</p>
  <pre><code>dta &lt;- data.frame(x = c('A','B','A','B'),
                    y = c('P','Q','Q','P'),
                    z = c(89,12,34,56)
                    ) |&gt; print()
      #&gt;   x y  z
      #&gt; 1 A P 89
      #&gt; 2 B Q 12
      #&gt; 3 A Q 34
      #&gt; 4 B P 56
      
  </code></pre>
  <p>The following is not what I am looking for.</p>
  <pre><code>  as.list(dta)
      #&gt; $x
      #&gt; [1] &quot;A&quot; &quot;B&quot; &quot;A&quot; &quot;B&quot;
      #&gt; $y
      #&gt; [1] &quot;P&quot; &quot;Q&quot; &quot;Q&quot; &quot;P&quot;
      #&gt; $z
      #&gt; [1] 89 12 34 56
  </code></pre>
  <p>What I am trying to do is to create a lookup table using <code>make_nested_list</code> such that
  <code>nested_dta = make_nested_list(dta)</code> and <code>nested_dta['A']['P']</code> will output <code>89</code>.
  <a href="https://stackoverflow.com/questions/66316828/r-dataframe-to-nested-list">This answer</a> is close but not useful for my case.
  I am trying to do this in base R so that it is more readable. <code>dplyr</code> can do this but seems wordy <code>library(tidyvserse);dta %&gt;% filter(x=='A',y=='P') %&gt;% pull(z)</code>. There are other use cases that may benefit from the base R formulation. Is there is a better way to create the nested dictionary? Thank you.</p>