Note: I registered github issue # 1448 regarding an error as a result of this answer.
Updated October 29, 2015 . It looks like this error in rowwise() fixed. See the link above for more details.
Firstly, there is no reason to do this in different ways.
As for the error, then NA is a logical type. You will need to use NA_real_ in your ifelse() call on this line. Or, as Ben Bolker notes in the comments below, you can wrap ifelse() with as.numeric() .
data.frame(k = rnorm(10)) %>% rowwise() %>% mutate(l = ifelse(k > 0, 1, NA_real_))
Note that you can also use integers, as in
mutate(l = ifelse(k > 0, 1L, NA_integer_))
But you cannot mix logics and reals / integers in different ways. It seems that
source share