title: Right way to use lm in R
body: <p>I do not have very clear idea of how to use functions like lm() that ask for a formula and a data.frame.
  On the web I red about different approach but sometimes R give us warnings and other stuff</p>
  
  <p>Suppose for example a linear model where the output vector y is explained by the  matrix X.</p>
  
  <p>I red that the best way is to use a data.frame (expecially if we are going to use the predict function later). </p>
  
  <p>In situation where the X is a matrix is this the best way to use lm?</p>
  
  <pre><code>n=100
  p=20
  n_new=50
  
  X=matrix(rnorm(n*p),n,p)
  Y=rnorm(n)
  data=list("x"=X,"y"=Y)
  l=lm(y~x,data)  
  
  X_new=matrix(rnorm(n_new*p),n_new,p)
  pred=predict(l,as.data.frame(X_new))
  </code></pre>