title: How to counter the 'non-numeric matrix extent' error in R?
body: <p>I'm trying to generate a data frame of simulated values from the student's t distribution using the standard stochastic equation. The function I use is as follows:</p>
  
  <pre><code>matgen&lt;-function(means,chi,covariancematrix)
  {
   cols&lt;-ncol(means);
   normals&lt;-mvrnorm(n=500,mu=means,Sigma = covariancematrix);
   invgammas&lt;-rigamma(n=500,alpha=chi/2,beta=chi/2);
   gen&lt;-as.data.frame(matrix(data=NA,ncol=cols,nrow=500));
   i&lt;-1;
   while(i&lt;=500)
   {
     gen[i,]&lt;-t(means)+normals[i,]*sqrt(invgammas[i]);
     i&lt;=i+1;
   }
  return(gen);
  }
  </code></pre>
  
  <p>If it's not clear, I'm trying to create an empty data frame, that takes in values in cols number of columns and 500 rows. The values are numeric, of course, and R tells me that in the 9th row:</p>
  
  <pre><code>gen&lt;-as.data.frame(matrix(data=NA,ncol=cols,nrow=500));
  </code></pre>
  
  <p>There's an error: 'non-numeric matrix extent'.</p>
  
  <p>I remember using <code>as.data.frame()</code> to convert matrices into data frames in the past, and it worked quite smoothly. Even with numbers. I have been out of touch for a while, though, and can't seem to recollect or find online a solution to this problem. I tried <code>is.numeric()</code>, <code>as.numeric()</code>, 0s instead of NA there, but nothing works.</p>