The mutate function from the R package "dplyr" has a peculiar recirculation function for factors, since it returns the coefficient as.numeric . In the following example, y becomes what you expect, while z is c(1,1)
library(dplyr) df <- data_frame(x=1:2) glimpse(df %>% mutate(y="A", z=factor("B"))) # Variables: # $ x (int) 1, 2 # $ y (chr) "A", "A" # $ z (int) 1, 1
Is there any justification for this, or is this a mistake?
(I am using R 3.1.1 and dplyr 0.3.0.1.)
EDIT:
After posting this github issue, Romain Francois installed it in a few hours! Therefore, if the above problem uses devtools::install_github to get the latest version:
library(devtools) install_github("hadley/dplyr")
and then
library(dplyr) df <- data_frame(x=1:2) glimpse(df %>% mutate(y="A", z=factor("B")))
Good work Romain!
source share