如何在R中按日期对数据框进行排序 [英] How to sort a data frame by date in R

查看:7981
本文介绍了如何在R中按日期对数据框进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello
我需要按日期在R中对数据框进行排序。日期全部采用dd / mm / yyyy的形式。日期在第3列。列标题为V3。我已经看到了如何按列排序数据框,我已经看到如何将字符串转换为日期值。我不能组合这两个,以便按日期对数据框进行排序。



谢谢
John

解决方案

假设你的数据框被命名为 d

  d [order(as.Date(d $ V3,format =%d /%m /%Y))]] 
pre>

阅读我的博文,,如果没有意义,


Hello I need to sort a data frame by date in R. The dates are all in the form of "dd/mm/yyyy". The dates are in the 3rd column. The column header is V3. I have seen how to sort a data frame by column and I have seen how to convert the string into a date value. I can't combine the two in order to sort the data frame by date.

Thank you John

解决方案

Assuming your data frame is named d,

d[order(as.Date(d$V3, format="%d/%m/%Y")),]

Read my blog post, Sorting a data frame by the contents of a column, if that doesn't make sense.

这篇关于如何在R中按日期对数据框进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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