So I have this dataset I am working in. It has records that are recording on a log and there some duplicates on ClientIDs. The reason there are duplicates is because a user can update the data with new information. I've included the dataset below
Timestamp ClientID Application_Date Expiration_Date
<chr> <chr> <chr> <chr>
1 12/9/2021 13:26:10 380925 12/8/2021 NA
2 12/9/2021 14:37:15 380925 12/9/2021 NA
3 12/14/2021 12:34:30 375889 12/14/2021 12/24/2021
4 12/14/2021 12:37:08 375889 12/14/2021 NA
5 12/14/2021 12:45:40 319956 12/14/2021 12/16/2021
So I have 3 distinct IDs here, 380925, 375889, and 319956. Using the timestamp column, I can see what data is the newest and most up to date. And I can confirm this in R by doing the following
> data %>%
+ group_by(ClientID) %>% count()
# A tibble: 3 x 2
# Groups: ClientID [3]
ClientID n
<chr> <int>
1 319956 1
2 375889 2
3 380925 2
Now if I would like to filter down to each ClientID's most recent recorded info, I was using this code.
data_output <- data %>%
group_by(ClientID) %>%
slice_max(as.POSIXct(Timestamp, format = "%d/%m/%Y %H:%M:%S")) %>%
ungroup() %>%
arrange(Timestamp)
The problem is my output is only 1 row when I was expecting 3 rows.
# A tibble: 1 x 4
Timestamp ClientID Application_Date Expiration_Date
<chr> <chr> <chr> <chr>
1 12/9/2021 14:37:15 380925 12/9/2021 NA
Why is this happening?
Data Below
data <- structure(list(Timestamp = c("12/9/2021 13:26:10", "12/9/2021 14:37:15",
"12/14/2021 12:34:30", "12/14/2021 12:37:08", "12/14/2021 12:45:40"
), ClientID = c("380925", "380925", "375889", "375889", "319956"
), Application_Date = c("12/8/2021", "12/9/2021", "12/14/2021",
"12/14/2021", "12/14/2021"), Expiration_Date = c(NA, NA, "12/24/2021",
NA, "12/16/2021")), row.names = c(NA, -5L), class = c("tbl_df",
"tbl", "data.frame"))