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

R:Rank方法将我的索引格式从Date更改为POSIXct,r,xts,posixct,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

我有以下问题。我有一个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)))
}

rankvaluations您没有提供一个可复制的示例,因此我无法尝试,但尝试将xts对象转换为zoo,执行排序并转换回以查看是否修复了它。没有安装
xts
,但根据我从文档中读取的内容,强制方法
as.xts
dateFormat
参数默认设置为
POSIXct
。也许您可以在调用
as.xts
时尝试使用
dateFormat=“Date”
> 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" ...