title: Finding correlation between two data sets in R
body: <p><strong>UPDATED DATA SET 2 and 1 STRUCTURE:</strong> Sorry for this sudden update. I have two data sets. The structure of my first data set is (when using <code>print(matr1)</code> in <code>R</code>):</p>
  
  <pre><code>        month_year  income
   [1,]  "Jan 2000"  "30000"
   [2,]  "Feb 2000"  "12364"
   [3,]  "Mar 2000"  "37485"
   [4,]  "Apr 2000"  "2000"
   [5,]  "Jun 2000"  "7573"
            .     .      .
            .     .      .
  </code></pre>
  
  <p><strong>Thus the first data set has</strong> <strong>one income value for each month of each year</strong>.</p>
  
  <p>The structure of my second data set is (when using <code>print(matr2)</code> in <code>R</code>):</p>
  
  <pre><code>     month_year     value
   [1,] "Jan 2000" "84737476"
   [2,] "Jan 2000" "39450334"
   [3,] "Jan 2000" "48384943"
   [4,] "Feb 2000" "12345678"
   [5,] "Feb 2000" "49595340"
  
            .     .      .
            .     .      .
  </code></pre>
  
  <p><strong>So in this second data set I have <code>n</code>(say 100 but not constant all the time) number of values for each month of each year.</strong></p>
  
  <p>Both the data sets have values month wise for many subsequent years(like for all the months for year 2000, 2001 and so on). Now I want to find the correlation between these two data sets but month-wise and not as whole. When I use the R command <code>cor(as.numeric(matr1[,"income"]),as.numeric(matr2[,"value"]))</code> then I get the overall correlation but I want the correlation per month rather than as a whole. <strong>I want the correlation something like this:</strong></p>
  
  <pre><code>                  Jan | Feb | Mar | Apr | May | .....
  Correlation        x  |  y  |  z  |  p  |  q  | .....
  </code></pre>
  
  <p>The issue that I have is:</p>
  
  <ol>
  <li>How do I get the correlation value per month instead of the overall correlation?</li>
  </ol>
  
  <p><strong>NOTE:</strong> I am not sure whether I should have posted this question here or on <code>Cross Validated</code>. I had posted a question for this data set only regarding an error in getting correlation and it was migrated from there to here. So please forgive if I am posting this on wrong place.</p>
  
  <p><strong>UPDATE1:</strong> After some suggestion I have modified this post to point in the correct dimension. First of all, the data sets as of now are in matrix format and hence the quotes. I can convert it to <code>data.frame</code> as suggested by some comments but right now I have been calculating the correlation by converting the columns using <code>as.numeric</code>.</p>