Reputation: 363
I have a dataset that looks like this :
Is there a way in dplyr to select the first observation of each group of weeknum and it's correpsonding date i know how to get the unique values but i don't know how to get their corresponding dates if you could help I would appreciate it.
Thank you in advance
Upvotes: 0
Views: 242
Reputation: 887951
We can use slice_head
after grouping by the 'weeknum'
library(dplyr)
df1 %>%
group_by(weeknum) %>%
slice_head(n = 1)
Or with distinct
df1 %>%
distinct(weeknum, .keep_all = TRUE)
In base R
, it can be done with duplicated
and subset
subset(df1, !duplicated(weeknum))
Upvotes: 1