Correlation with different vector length - same time period - Cross Validated most recent 30 from stats.stackexchange.com 2019-09-20T03:33:11Z https://stats.stackexchange.com/feeds/question/46891 https://creativecommons.org/licenses/by-sa/4.0/rdf https://stats.stackexchange.com/q/46891 3 Correlation with different vector length - same time period user1554592 https://stats.stackexchange.com/users/18396 2013-01-03T15:16:26Z 2013-01-06T13:10:06Z <p>I have a data set containing equity price information on a tick by tick basis. I would like to calculate the correlation in R, which isn't a hassle. But the vectors are of different length due to one equity being traded more than the other. </p> <p>I can aggregate on a minute basis, but this also leaves the vectors of inequal length due to trades not occuring each minute for each equity. </p> <p>I guess it boils down to a statisical question. Can I calculate the correlation with different vector length given they sample the same time period? I thought about inputting the previous price in the empty time minute slots to achieve equal vector length, but perhaps there is a different approach?</p> <p>I am using R. </p> <p>Thanks</p> <hr> <p>Thank you for your answers. I have looked into the proposed solutions, and I think an upsampling / downsampling will be best in this case. </p> <p>Is there a way to code the following in R? My hunch is an if loop that will check the corresponding data frame if the time is present if not then it will grabthe previous price and input a new price for the missing time. </p> <p>This is what I would like to produce: </p> <p>Two seperate colums, price and time, for each equity. If the time is present for equity X but not equity Y then the previous price should put into the vector. As per the following example: </p> <pre><code>X Y price time price time 10 540 20 540 11 541 21 541 12 542 22 543 13 544 23 544 14 545 24 545 price time price time 10 540 20 540 11 541 21 541 12 542 21 542 12 543 22 543 13 544 23 544 14 545 24 545 </code></pre> https://stats.stackexchange.com/questions/46891/-/46892#46892 2 Answer by Hélio Santos for Correlation with different vector length - same time period Hélio Santos https://stats.stackexchange.com/users/0 2013-01-03T15:35:44Z 2013-01-03T15:35:44Z <p>You can <a href="http://en.wikipedia.org/wiki/Upsampling" rel="nofollow">upsample</a> the smaller vector or <a href="http://en.wikipedia.org/wiki/Downsampling" rel="nofollow">downsample</a> the lager one.</p> <p>Then use the standard correlation function.</p>