Here is my df:
tmp2 <- structure(list(a = 1:10, b = c(88L, 54L, 17L, 88L, 57L, 52L, 65L, 12L, 16L, 60L)), row.names = c(NA, -10L), class = c("tbl_df", "tbl", "data.frame"))
I want to add new column with mutate() and case_when, provided that: b==17 I will do a*2.
The other values in a and b columns I want to leave intact.
tmp2 %>% dplyr::mutate(new_col = dplyr::case_when( b == 17 ~ a*2, TRUE ~ b))
is not working.
tmp2 %>% dplyr::mutate(new_col = dplyr::case_when( b == 17 ~ a*2, TRUE ~ b+0))
is working, giving me what I want:
Why does not "b" working alone in the formula and I must add: "b+0" to make it work ?
Any explanation would be appreciated.