My ifelse statement: df$baseline <- ifelse(df$value <= -20, "yes", "")
However, I only want it labelled "yes" for the first occurrence of the -20 value for each id. For example, id = 3
should only have a 'yes'
for the value = -46.96
.
Can this even be done with just an ifelse statement since it has to be grouped by id?
id value yes
1 1 NA <NA>
2 1 -27.17 yes
3 2 NA <NA>
4 2 -18.69
5 2 17.27
6 2 -34.38 yes
7 3 NA <NA>
8 3 134.50
9 3 -46.96 yes
10 3 88.18
11 3 -32.27 yes -> SHOULD BE ""
12 3 -0.40
13 3 36.69