my issue is the following:
I have a tibble which I want to modify with 3 different cases:
- All values in group are
NA
- At least one but not all are
NA
. In this case replaceNA
with an arbitrary value (ex:0.5
) - None are
NA
Example: (with group_by
ind
)
a1 = c(0.3,0.1,NA,0.7,0.2)
a2 = rep(NA,5)
a3 = c(0.1,0.3,0.5,0.7,0.8)
tibble(ind = c(rep("A",5),rep("B",5),rep("C",5)),
value = c(a1,a2,a3)
segment of group A
should yield c(0.3,0.1,0.5,0.7,0.2)
segment of group B
should yield rep(NA,5)
segment of group C
should stay the same
I've tried with if
, ifelse
and case_when
statements but I think I'm missing something very obvious. All help is appreciated.