title: How can I unlist a nested list and keep the names of the sublist (as is) and the names of the elements?
body: <p>I have a nested list with 3 levels:</p>
  
  <ol>
  <li><p>length of string (I don't care about that when all is done, it's just for the ordering of the lists)</p></li>
  <li><p>Category (I want to keep this in the output)</p></li>
  <li><p>Elements (strings I also want to keep)</p></li>
  </ol>
  
  <p>I want to unlist/flatten this construct to get a character vector with the order in the list and all elements should be named:</p>
  
  <p>"Category""_""Element"</p>
  
  <p>I cannot get this done. My problem is that either level 2 is not kept as a name or that it keeps the index as well so I get wrong names (e.g. Dog, Dog1, Dog2, Dog3 instead of Dog).</p>
  
  <p>I have tried first purrr::flatten -> the resulting list looks good (I think). </p>
  
  <p>Then I tried unlist of the flattened output to get all these items into a character vector and this is, where it gets me.</p>
  
  <p>I receive names of the elements like:</p>
  
  <p>TCRBV11-031 TCRBV11-032 TCRBV11-033</p>
  
  <p>but they should all be TCRBV11-03</p>
  
  <p>How can I keep the name of the sublist and combine it with the element. Preferably with a "_" in-between?</p>
  
  <p>Edit: dput of an example list:</p>
  
  <pre><code>list(`11` = list(`TCRBV06-01` = "CAIDRSYEQYF", `TCRBV29-01` = "CSADRKETQYF"), 
      `12` = list(`TCRBV05-06` = "CASSRPNTEAFF", `TCRBV06-01` = "CASGHKNTEAFF", 
          `TCRBV07-03` = "CASSLRLHEQYF"), `13` = list(`TCRBV02-01` = "CASQGIVGYEQYF", 
          `TCRBV05-01` = "CASTGSLNTEAFF", `TCRBV06-04` = "CASSLGKNTEAFF", 
          `TCRBV07-03` = "CASSLTEGGGYTF", `TCRBV07-08` = "CASSPDTNTEAFF", 
          `TCRBV07-09` = "CASSPDRDTEAFF", `TCRBV10-03` = "CAISMISNQPQHF", 
          `TCRBV18-01` = "CASSPPETYEQYF", `TCRBV19-01` = "CASSIGGSTEAFF", 
          `TCRBV20-01` = c("CSAMAYRADGYTF", "CSAREAQAETQYF", "CSAITSRVDGYTF"
          ), `TCRBV27-01` = "CASSFPGGYGYTF"), `14` = list(`TCRBV05-06` = "CASSLVGASYEQYF", 
          `TCRBV06-01` = c("CASRQGQENQPQHF", "CASRRQGEGTEAFF"), 
          `TCRBV07-09` = "CASSPGVSGNTIYF", `TCRBV10-02` = "CASSPAEGGYEQYF", 
          `TCRBV13-01` = "CASSLGQGVYEQYF", `TCRBV24-01` = "CATRSTGANTEAFF"), 
      `15` = list(`TCRBV02-01` = "CASSDVLAGGPEQYF", `TCRBV04-01` = "CASSQDPAGGRKLFF", 
          `TCRBV04-03` = "CASSQDSTALYGYTF", `TCRBV05-01` = "CASSFEDRGAGGYTF", 
          `TCRBV05-04` = c("CASGLTGEGNTEAFF", "CASSPVSSRTDTQYF"
          ), `TCRBV06-04` = "CASSDSSSGYNEQFF", `TCRBV07-09` = "CASSPTSGVGSEQFF", 
          `TCRBV10-03` = "CAISGGGGSTNIQYF", `TCRBV11-03` = "CASSDETGAGYEQFF", 
          `TCRBV13-01` = "CASSSSTALYNEQFF", `TCRBV18-01` = "CASSPLAGGSNEQYF", 
          `TCRBV25-01` = "CASSEDRGLDQPQHF", `TCRBV28-01` = "CASSPVAGGHYEQYF", 
          `TCRBV30-01` = "CAWSWGGGLGEKLFF"), `16` = list(`TCRBV04-01` = "CASSQVVIPPGEKLFF", 
          `TCRBV14-01` = "CASSQPGLLGTDTQYF", `TCRBV15-01` = "CATSRWGTGELTEAFF", 
          `TCRBV19-01` = "CASSIGTADIYNEQFF", `TCRBV20-01` = "CSARGQTSGFTYEQYF"), 
      `17` = list(`TCRBV04-01` = "CASSQDPRTASYNEQFF", `TCRBV04-02` = "CASSQDLETSGDDIQYF", 
          `TCRBV25-01` = "CASSEYTTGEVTDTQYF"), `18` = list(`TCRBV12-05` = "CASGLVGGVLSGANVLTF"), 
      `19` = list(`TCRBV04-03` = "CASSQDPKGGLLNTGELFF"))
  </code></pre>