根据格式为%d /%m /%Y的日期按时间顺序订购数据框 [英] Order dataframe chronologically based on dates which are formatted %d/%m/%Y

查看:121
本文介绍了根据格式为%d /%m /%Y的日期按时间顺序订购数据框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些数据必须格式化为(%d /%m /%Y)。数据不按时间顺序排列,因为它是按第一个数字(即日期而不是月份)排序的。

I have some data that has to be formatted as (%d/%m/%Y). The data is out of chronological order because it is sorted by the first number which is the day, not the month.

我希望我可以指定订单再订购我希望排序发生不同。我只是不确定如何执行此操作。

I'm hoping I can specify to order or reorder that I want the sorting to happen differently. I'm just not sure how to do this.

以下是一些要订购的日期数据:

Here is some date data to be ordered:

date
1/1/2009  
1/1/2010
1/1/2011
5/4/2009
5/4/2011
10/2/2009
10/3/2011
15/9/2010
15/3/2009
31/12/2011
31/7/2009

感谢任何建议。

推荐答案

按列 date 排序时,将其转换为日期格式。

When order by column date convert it Date format.

df[order(as.Date(df$date,format="%d/%m/%Y")),,drop=FALSE]
         date
1    1/1/2009
6   10/2/2009
9   15/3/2009
4    5/4/2009
11  31/7/2009
2    1/1/2010
8   15/9/2010
3    1/1/2011
7   10/3/2011
5    5/4/2011
10 31/12/2011

这篇关于根据格式为%d /%m /%Y的日期按时间顺序订购数据框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆