如何对xts对象进行逆序排序

问题描述 投票:0回答:1

我正在尝试进行常规反向排序,但我不明白如何使用

xts
对象进行排序。我希望最后一个日期位于第一行而不是最后一行。 我尝试了多种方法,但都不起作用。

library(xts)
x <- rnorm(500) |> cumsum() |> round(1) |> 
                  xts(Sys.time()+1:500) |> to.minutes(name = NULL) 

# dont work :(

# x[nrow(x):1,]
# x[order(index(x),decreasing = T),]
# rev(x)
r sorting xts
1个回答
0
投票
library(xts)
x <- rnorm(500) |> cumsum() |> round(1) |> 
      sort(decreasing = TRUE) |> 
      xts(Sys.time()+1:500) |> to.minutes(name = NULL) 
© www.soinside.com 2019 - 2024. All rights reserved.