'Keep distinct values in List

I have a list of values created based on date variable. I would like to delete historical date containing rows while keeping the latest date. Which function will work best?

enter image description here

r


Solution 1:[1]

Maybe something like this if the input is a dataframe ...

library(tidyverse)
library(lubridate)
#> 
#> Attaching package: 'lubridate'
#> The following objects are masked from 'package:base':
#> 
#>     date, intersect, setdiff, union

unfiltered_df <- 
  tribble(
  ~date, ~cif, ~mti, ~mtb,
  "2021/05/24", 1, 2, 1,
  "2020/07/10", 1, 1, 1,
  "2019/04/01", 1, 1, 1,
  "2018/05/01", 1, 1, 2
) |> 
  mutate(date = ymd(date))

unfiltered_df |> 
  filter(date == max(date))
#> # A tibble: 1 × 4
#>   date         cif   mti   mtb
#>   <date>     <dbl> <dbl> <dbl>
#> 1 2021-05-24     1     2     1

Created on 2022-04-19 by the reprex package (v2.0.1)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Carl