I want to use the pipe function
of dplyr
package to change values of a column conditionally. I used below approach -
library(dplyr)
> df = data.frame("Col1" = letters[1:6], "Col2" = 1:6)
> df %>% mutate(Col3 = ifelse(Col1 == "a", "aa", Col1))
Col1 Col2 Col3
1 a 1 aa
2 b 2 2
3 c 3 3
4 d 4 4
5 e 5 5
6 f 6 6
In above result, the first value of Col3
is correctly assigned but not rest. Can someone please help me to understand the correct approach?