title: Creating a R data frame in C/C++
body: <p>I'm trying to make a data.frame to pass into R  code from C/C++ code (I'm not using Rcpp, I want to use the R c-api from first principles for reasons not relevant here)</p>
  
  <p>I know how to make a vector of doubles and load with data (just dummy data here for my example)</p>
  
  <pre><code>SEXP col1;
  Rf_protect(col1= Rf_allocVector(REALSXP, 10);
  for (size_t j = 0; j &lt; 10; j++)
  {
       double dval = static_cast&lt;double(j*3.14);
       REAL(col1)[static_cast&lt;int&gt;(j)] = dval;
  }
  SEXP nameSym = Rf_install(const_cast&lt;char*&gt;("myColumn1"));
  Rf_defineVar(nameSym, col1, _R_GlobalEnv);
  </code></pre>
  
  <p>And this works such that inside R I can do</p>
  
  <pre><code>Y &lt;- mean(myColumn1)
  </code></pre>
  
  <p>but what I really want to do is have a dataframe with more than 1 column in</p>
  
  <pre><code>SEXP col1;
  SEXP col2;
  Rf_protect(col1= Rf_allocVector(REALSXP, 10);
  Rf_protect(col2 = Rf_allocVector(REALSXP, 10);
      for (size_t j = 0; j &lt; 10; j++)
      {
           double dval1 = static_cast&lt;double(j*3.14);
           double dval2 = static_cast&lt;double(j*42.0);
           REAL(col1)[static_cast&lt;int&gt;(j)] = dval1;
           REAL(col2)[static_cast&lt;int&gt;(j)] = dval2;
      }
      SEXP nameSym1 = Rf_install(const_cast&lt;char*&gt;("myColumn1"));
      SEXP nameSym2 = Rf_install(const_cast&lt;char*&gt;("myColumn2"));
      Rf_defineVar(nameSym1, col1, _R_GlobalEnv);
      Rf_defineVar(nameSym2, col2, _R_GlobalEnv);
  
      .... data.frame?
  </code></pre>
  
  <p>Ideally I'd like to put myColumn1 and myColumn2 into a data,frame ("myData") so I can do</p>
  
  <pre><code>Y &lt;- mean(myData$myColumn1)
  Z &lt;- min(myData$myColumn2)
  </code></pre>
  
  <p>Does anyone know how to construct a data frame?</p>
  
  <p>Any pointers would be helpful</p>