R:Rank方法将我的索引格式从Date更改为POSIXct

时间:2014-09-09 13:44:01

标签: r xts posixct

我有以下问题。我有一个XTS包含一个日期列和几个估值,应该排名(最大=最佳排名)。所以我的原始XTS是测试:

> str(index(Test))
Date[1:235], format: "1995-01-31" "1995-02-28" "1995-03-31" "1995-04-28" "1995-05-31" "1995-06-30" "1995-07-31" ...

现在,我的rankValuations功能:

rankValuations<-function(ValuationXTS){
  #Ranks the xts object asset valuations 
  #ValuationXTS is a xts time series with asset valuations
  #Returns an xts object with ranks (asset with the greatest valuation receives 1)
  #The ties parameter results in an ascending ranking. If two share the same rank, the first in the matrix gets the first rank
  ranked<-as.xts(t(apply(-ValuationXTS,1,rank, ties.method="first",na.last=TRUE)))
}

运行此操作后,我的索引格式已更改为POSIX:

> Test<-rankValuations(Test)
> str(index(Test))
 POSIXct[1:235], format: "1995-01-31" "1995-02-28" "1995-03-31" "1995-04-28" "1995-05-31" "1995-06-30" "1995-07-31" ...

这是一个很大的问题,因为在POSIX中我现在有了一个时区。如果稍后在merge.xts上使用它,它永远不会匹配,因为POSIX日期比在与具有Date索引的XTS合并之前1天。那么如何才能停止将Date更改为POSIX的等级方法?

0 个答案:

没有答案