Why does dplyr error in this nested if_else, when logical condition means output should not be evaluated?
问题 I have a nested if_else statement inside mutate . In my example data frame: tmp_df2 <- data.frame(a = c(1,1,2), b = c(T,F,T), c = c(1,2,3)) a b c 1 1 TRUE 1 2 1 FALSE 2 3 2 TRUE 3 I wish to group by a and then perform operations based on whether a group has one or two rows. I would have thought this nested if_else would suffice: tmp_df2 %>% group_by(a) %>% mutate(tmp_check = n() == 1) %>% mutate(d = if_else(tmp_check, # check for number of entries in group 0, if_else(b, sum(c)/c[b == T], sum