在 r 中获取具有最大日期的所有相应行 [英] Getting all the corresponding rows with max date in r

查看:142
本文介绍了在 r 中获取具有最大日期的所有相应行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有与此类似的数据框,但还有 30 个变量

I have the data frame similar to this but with 30 more variables

我只需要每个代码"对应的最大日期值所以输出应该是这样的

i need only the corresponding values of max date for each "code" so the output should be like this

任何专家都可以帮我解决这个问题.

Any experts can help me solving this please .

推荐答案

也可以使用 dplyr 来完成(假设你的数据是一个名为 dt 的数据框):

It can also be done using dplyr (assuming your data is a data frame called dt):

library(dplyr)

dt %>% group_by(code) %>% filter(Date == max(Date))

这篇关于在 r 中获取具有最大日期的所有相应行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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