如何按日期对数据框进行排序 [英] How to sort a data frame by date
本文介绍了如何按日期对数据框进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要按R中的日期对数据框进行排序.日期全部以"dd/mm/yyyy"的形式出现.日期在第3列中.列标题是V3.我已经看到了如何按列对数据帧进行排序,并且已经看到了如何将字符串转换为日期值.我无法将两者结合在一起以按日期对数据框进行排序.
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.
推荐答案
假定您的数据框名为d
,
d[order(as.Date(d$V3, format="%d/%m/%Y")),]
阅读我的博客文章 查看全文