Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个包含两列的矩阵。我想计算两列之间的“运行”60 天相关性。是否有可能以 R 方式执行此操作,即不使用 for/while 循环。
基本上我的 t 日计算将基于 (t-60:t) 而 t-1 日将基于 (t-61:t-1) 等等。
如果你的矩阵是 m 那么...
b <- 60 sapply( b:nrow(m), function(t) cor(m[(t-b):t,] )