我想每天对一组变量进行排名(从zoo
一系列开始)。
这是一个例子:
set.seed(1)
x <- zoo(matrix(rnorm(9), nrow=3), as.Date("2010-01-01") + 0:2)
colnames(x) <- letters[1:3]
我知道这样做的唯一方法是使用rollapply
,但这很慢。
> rollapply(x, 1, rank, by.column=FALSE)
a b c
2010-01-01 1 3 2
2010-01-02 1 2 3
2010-01-03 1 2 3
还有其他建议吗?