title: how to create a list in R from two vectors (one would be the keys, the other the values)?
body: <p>I have two vectors and I want to create a list in R where one vector are the keys and the other the values. I thought that I was going to find easily the answer in my books or googleing around and I was expecting to find a solution like when adding names to a vector ( names(v)&lt;- names_vector), but I failed. </p>
  
  <p>I have come myself with two possible solutions but none of them seems elegant to me. R is not my main programming language but I assume that being R so pragmatic a better solution should exist (something like list(keys=x, values=y)).</p>
  
  <p>My solution 1: the classical loop solution:</p>
  
  <pre><code>    &gt; xx &lt;- 1:3
      &gt; yy &lt;- letters1:3
      &gt; zz =list()
      &gt;for(i in 1:length(yy)) {zz[[yy[i]]]&lt;-xx[i]}
  </code></pre>
  
  <p>my solution 2: indirect path through named vectors:</p>
  
  <pre><code>    &gt; names(xx) &lt;- letters[1:3]
      &gt; as.list(xx)
  </code></pre>
  
  <p>Seems that I have a solution, but my vectors have 1 million or more elements  and I am worried not only about coding style (important to me) but also about efficiency (but I don't know how to do profiling in R). Is there a more appropriate way of doing this? Is it a good practice to use the named vector shortcut?</p>
  
  <p>[[UPDATE]] my applogies, probably I oversimplify the question to make it reproducible. I wanted to give names to the elements of a list. I tried names() first but seems that I did something wrong and did not work. So I got the wrong idea that names() does not work with lists. But they indeed do as shown by the accepted answer</p>