-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mutate_if applies fun to all columns if predicate returns all false #2181
Comments
duplicates of #2009 and #1989 and already fixed in dev version by #2011 . With devtools::dev_mode()
#> Dev mode: OFF
library(dplyr) # dev version 0.5.0.9000
df1 <- data_frame(
a = 1:10,
b = runif(10),
c = letters[1:10]
)
df2 <- data_frame(
a = 1:10,
b = runif(10),
c = 10:1
)
# works as intended, c is converted to a factor
glimpse(df1)
#> Observations: 10
#> Variables: 3
#> $ a <int> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
#> $ b <dbl> 0.32494503, 0.73370927, 0.90391393, 0.79685123, 0.09798207, ...
#> $ c <chr> "a", "b", "c", "d", "e", "f", "g", "h", "i", "j"
df1 %>% mutate_if(is.character, as.factor) %>% glimpse()
#> Observations: 10
#> Variables: 3
#> $ a <int> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
#> $ b <dbl> 0.32494503, 0.73370927, 0.90391393, 0.79685123, 0.09798207, ...
#> $ c <fctr> a, b, c, d, e, f, g, h, i, j
# all columns stays the same
glimpse(df2)
#> Observations: 10
#> Variables: 3
#> $ a <int> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
#> $ b <dbl> 0.67622567, 0.53826781, 0.31735237, 0.99455487, 0.20520285, ...
#> $ c <int> 10, 9, 8, 7, 6, 5, 4, 3, 2, 1
df2 %>% mutate_if(is.character, as.factor) %>% glimpse()
#> Observations: 10
#> Variables: 3
#> $ a <int> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
#> $ b <dbl> 0.67622567, 0.53826781, 0.31735237, 0.99455487, 0.20520285, ...
#> $ c <int> 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 |
Fixed in #2011 |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
The text was updated successfully, but these errors were encountered: