creating pre to post labels from visit day/time

Viewed 33

I have this data set in where participants were given a visit day. So in order to differentiate when pre testing happens and post testing happens I need to first match them to their participant id.

I would like to mutate the lower value from visit time to "pre" and the higher value to "post"? any ideas how I can achieve this? Thank you very much!

enter image description here

1 Answers

I think you would want something like this:

df %>% 
  group_by(ID) %>% 
  mutate(pre = min(Visit),
         post = max(Visit)) %>% 
  ungroup()
Related