如何在R中反转数据帧的顺序 [英] How to reverse the order of a dataframe in R

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

问题描述

我一直在寻找这个问题,以某种方式无法解决这个简单问题.

I've endlessly looked for this and somehow nothing has solved this simple problem.

我有一个称为价格的数据框,其中有4列,其中一列是历史日期列表,其他三列是产品价格列表.

I have a dataframe called Prices in which there are 4 columns, one of which is a list of historical dates - the other 3 are lists of prices for products.

1   10/10/2016  53.14   50.366  51.87
2   07/10/2016  51.93   49.207  50.38
3   06/10/2016  52.51   49.655  50.98
4   05/10/2016  51.86   49.076  50.38
5   04/10/2016  50.87   48.186  49.3
6   03/10/2016  50.89   48.075  49.4
7   30/09/2016  50.19   47.384  48.82
8   29/09/2016  49.81   46.924  48.4
9   28/09/2016  49.24   46.062  47.65
10  27/09/2016  46.52   43.599  45.24

此列表长252个价格.如何将输出存储为最新日期在列表底部,将相应的价格存储为最新价格在列表底部?

The list is 252 prices long. How can I have my output stored with the latest date at the bottom of the list and the corresponding prices listed with the latest prices at the bottom of the list?

推荐答案

另一种tidyverse解决方案,我认为最简单的解决方案是:

Another tidyverse solution and I think the simplest one is:

df %>% map_df(rev)

或仅使用purrr::map_df我们就可以执行map_df(df, rev).

or using just purrr::map_df we can do map_df(df, rev).

这篇关于如何在R中反转数据帧的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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