Hi,
Welcome to the RStudio community!
I agree with @williaml on the reprex, but since it's your first post and I was working on it while he posted as well, I shall share my reply too with your data in the form of a reprex
library(dplyr)
myData = data.frame(
stringsAsFactors = FALSE,
pID = c(1L, 1L, 1L, 1L, 2L, 2L),
sID = c(100L, 200L, 300L, 400L, 500L, 600L),
date = c("2016-06-20 00:00:00",
"2016-06-21 00:00:00",
"2016-06-22 00:00:00","2016-06-23 00:00:00",
"2016-06-24 00:00:00",
"2016-06-25 00:00:00"),
count = c(1L, 2L, 3L, 4L, 2L, 3L),
age = c(77L, 77L, 77L, 77L, 55L, 55L),
other = c(10L, 22L, 34L, 46L, 58L, 70L)
)
#Make date a date format
myData = myData %>%
mutate(date = as.POSIXct(date))
#Filter
myData = myData %>%
group_by(pID) %>%
filter(date == min(date) | count == min(count))
myData
#> # A tibble: 2 x 6
#> # Groups: pID [2]
#> pID sID date count age other
#> <int> <int> <dttm> <int> <int> <int>
#> 1 1 100 2016-06-20 00:00:00 1 77 10
#> 2 2 500 2016-06-24 00:00:00 2 55 58
Created on 2021-08-08 by the reprex package (v2.0.0)
You should read more about all of the Tidyverse functions, in this case especially dplyr.
Good luck
PJ