title: Linear Regression in R for Date and some dependant output
body: <p>Actually I need to calculate the parameters theta0 and theta1 using linear regression. 
  My data frame (data.1) consists of two columns, first one is a date-time and the second one is a result which is dependent on this date.<br/>
  Like this:</p>
  
  <pre><code>        data.1[[1]]  data.1[[2]]
  2004-07-08 14:30:00        12.41
  </code></pre>
  
  <p>Now, I have this code for which iterates over a number of times to calculate the parameter <code>theta0</code>, <code>theta1</code></p>
  
  <pre><code>x=as.vector(data.1[[1]])
  y=as.vector(data.1[[2]])
  
  plot(x,y)
  
  theta0=10
  theta1=10
  alpha=0.0001
  initialJ=100000
  learningIterations=200000
  
  J=function(x,y,theta0,theta1){
  m=length(x)
  sum=0
  for(i in 1:m){
    sum=sum+((theta0+theta1*x[i]-y[i])^2)
  }
  sum=sum/(2*m)
  return(sum)
  }
  
  updateTheta=function(x,y,theta0,theta1){
  sum0=0
  sum1=0
  m=length(x)
  for(i in 1:m){
     sum0=sum0+(theta0+theta1*x[i]-y[i])
     sum1=sum1+((theta0+theta1*x[i]-y[i])*x[i])
   }
  sum0=sum0/m
  sum1=sum1/m
  theta0=theta0-(alpha*sum0)
  theta1=theta1-(alpha*sum1)
   return(c(theta0,theta1))
  }    
  
  for(i in 1:learningIterations){
  thetas=updateTheta(x,y,theta0,theta1)
  tempSoln=0
  tempSoln=J(x,y,theta0,theta1)
  if(tempSoln&lt;initialJ){
    initialJ=tempSoln
  }
  if(tempSoln&gt;initialJ){
     break
   }
  theta0=thetas[1]
  theta1=thetas[2]
  #print(thetas)
  #print(initialJ)
  plot(x,y)
  lines(x,(theta0+theta1*x), col="red")
    }
    lines(x,(theta0+theta1*x), col="green")
  </code></pre>
  
  <p>Now I want to calculate theta0 and theta1 using the following scenarios:<br/></p>
  
  <ol>
  <li><code>y=data.1[[2]]</code> and <code>x=dates</code> which are similar irrespective of the year</li>
  <li><code>y=data.1[[2]]</code> and <code>x=months</code> which are similar irrespective of the year</li>
  </ol>
  
  <p>Please suggest..</p>