I have two lists, listA and listB which I would like to calculate the correlation between them using a rolling window of size 4.
listA A B C D 1) 1 3 4 6 2) 6 9 11 1 3) 1 3 4 5 4) 8 4 5 6 5) 9 9 4 6 6) 1 5 6 6 7) 9 3 6 4 8) 6 7 8 9 listB A B C D 1) 1 3 4 3 2) 6 9 5 7 3) 1 1 4 5 4) 7 1 5 6 5) 9 9 3 6 6) 1 5 6 6 7) 9 9 6 4 8) 5 6 4 9 Specifically I wish to calculate the cor(listA[1:4,1],listB[1:4,1]) using a rolling window of size 4 which means I'll have 5 values for the correlation between listA and listB for column A. Once this is done for column A I then would like to do the same for column B, C and D.
I have previously achieved this using 'rollapplyr' but the object I was working on was an XTS object and not two individual objects which for my simple little brain made it easier to comprehend.
'result <- rollapplyr(XTSobject, 4, cor, by.column = FALSE)' Can anyone suggest a way to do this between two lists?