0

I have a dataframe that has a factor list of 'before', 'during' and 'after'. I don't want duplicates of these if there is overlap in the summarize dataframe. So I'd like the code to just assign the first factor in the code and ignore any ones in the group.

Currently I have this code:

group_by(eventID) %>%
summarize(
  event = paste(unique(Event)))

However this creates two rows if the eventID overlaps two factors. How can I just get it to paste the first factor? ie. 'before' only not 'during'.

This is what the current code produces. I want there to only be one instance of this rainfall event. which starts and ends at the same time. Instead of producing two rows.

enter image description here

Melanie Baker
  • 449
  • 1
  • 13
  • Please provdie a minimal reproducible data and your expected outcom. You could copy/paste the output of `dput(eventID)` to your post. – Darren Tsai Jul 22 '22 at 08:02
  • 2
    While waiting for a reproducible data, would it work if you replace `paste(unique(Event))` by `unique(Event)[1]`? – DoRemy95 Jul 22 '22 at 08:03
  • Need code to say for sure but there is also a `first` function that sounds like it will be what you want – Quixotic22 Jul 22 '22 at 08:04
  • 1
    Does this answer your question? [Select the first row by group](https://stackoverflow.com/questions/13279582/select-the-first-row-by-group) – harre Jul 22 '22 at 09:47

0 Answers0