UPDATED DATA SET 2 and 1 STRUCTURE: Sorry for this sudden update. I have two data sets. The structure of my first data set is (when using print(matr1)
in R
):
month_year income
[1,] "Jan 2000" "30000"
[2,] "Feb 2000" "12364"
[3,] "Mar 2000" "37485"
[4,] "Apr 2000" "2000"
[5,] "Jun 2000" "7573"
. . .
. . .
Thus the first data set has one income value for each month of each year.
The structure of my second data set is (when using print(matr2)
in R
):
month_year value
[1,] "Jan 2000" "84737476"
[2,] "Jan 2000" "39450334"
[3,] "Jan 2000" "48384943"
[4,] "Feb 2000" "12345678"
[5,] "Feb 2000" "49595340"
. . .
. . .
So in this second data set I have n
(say 100 but not constant all the time) number of values for each month of each year.
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 cor(as.numeric(matr1[,"income"]),as.numeric(matr2[,"value"]))
then I get the overall correlation but I want the correlation per month rather than as a whole. I want the correlation something like this:
Jan | Feb | Mar | Apr | May | .....
Correlation x | y | z | p | q | .....
The issue that I have is:
- How do I get the correlation value per month instead of the overall correlation?
NOTE: I am not sure whether I should have posted this question here or on Cross Validated
. 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.
UPDATE1: 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 data.frame
as suggested by some comments but right now I have been calculating the correlation by converting the columns using as.numeric
.
data.frame
orts
object would be more appropriate for these sort of matters. – Roman Luštrik