有人可以帮我解决这个问题吗,我需要按递增顺序对数据集的时间进行排序。我该怎么做?
Input:
11:00 02:40 05:50 03:20
1 1 1 1
0 1 1 1
0 1 1 1
Output:
02:40 03:20 05:50 11:00
1 1 1 1
1 1 1 0
1 1 1 0
Sample data:
df<-structure(list(c("11:00", 1, 0, 0),
c("02:40", 1, 1, 1), c("05:50", 1, 1, 1), c("03:20", 1, 1,1)), row.names = c(NA,4L), class = "data.frame")
最佳答案
使用chron
和order
df[order(chron::times(paste0(df[1,], ":00")))]
#1 02:40 03:20 05:50 11:00
#2 1 1 1 1
#3 1 1 1 0
#4 1 1 1 0
关于r - 根据时间步长对数据进行排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63919235/