Hi All,
How can I proceed to estimate the correlation of 4 variables( cor(a,b) and cor(c,d) ) for each month?
I prefer to use aggregate and I tried the code below. variables are not able to recognize x and y.
I would be glad if you can suggest it.
Thanks
date=seq(as.Date("2020/1/1"), as.Date("2020/5/1"), "days")
a=rnorm(length(date))
b=rnorm(length(date))
c=rnorm(length(date))
d=rnorm(length(date))
dat <- data.frame(date,a,b,c,d)
dat$month=format(as.Date(dat$date, format="%Y-%m-%d"),"%m")
head(dat)
aggregate( cbind(c(a,b),c(c,d))~ month, dat, cor)
I am expecting the following output
Month cor(a,b), cor(c,d)
1 aa bb
2 cc dd
3 ee ff
4 gg hh
5 ii jj