-
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 does not behave as expected #2208
Labels
bug
an unexpected problem or unintended behavior
Comments
Duplicates of #2181, #2009, #1989 and already fixed in dev version by #2011 . library(dplyr) # dev version 0.5.0.9000
sampleData <- tibble::tibble(numbers = 1:10, factors = factor(sample(letters[1:3], size = 10, replace = T)))
# does work
sampleData %>%
mutate_if(is.factor, funs(length))
#> # A tibble: 10 x 2
#> numbers factors
#> <int> <int>
#> 1 1 10
#> 2 2 10
#> 3 3 10
#> 4 4 10
#> 5 5 10
#> 6 6 10
#> 7 7 10
#> 8 8 10
#> 9 9 10
#> 10 10 10
# does work
sampleData %>%
mutate_if(is.numeric, funs(mean))
#> # A tibble: 10 x 2
#> numbers factors
#> <dbl> <fctr>
#> 1 5.5 b
#> 2 5.5 b
#> 3 5.5 a
#> 4 5.5 b
#> 5 5.5 a
#> 6 5.5 a
#> 7 5.5 a
#> 8 5.5 a
#> 9 5.5 a
#> 10 5.5 c
# does work -> expect no changes to factor column
sampleData %>%
select(- numbers) %>%
mutate_if(is.numeric, funs(mean))
#> # A tibble: 10 x 1
#> factors
#> <fctr>
#> 1 b
#> 2 b
#> 3 a
#> 4 b
#> 5 a
#> 6 a
#> 7 a
#> 8 a
#> 9 a
#> 10 c
# does work -> expect no changes to numbers column
sampleData %>%
select(- factors) %>%
mutate_if(is.factor, funs(length))
#> # A tibble: 10 x 1
#> numbers
#> <int>
#> 1 1
#> 2 2
#> 3 3
#> 4 4
#> 5 5
#> 6 6
#> 7 7
#> 8 8
#> 9 9
#> 10 10 |
Works for me as advertised by @cderv in the dev version. |
@cderv thanks for collecting the related issues together! |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
It seems
mutate_if
modifies all columns if.predicate
returns an empty number of columnsUsing
dplyr * 0.5.0 2016-06-24 CRAN (R 3.3.1)
The text was updated successfully, but these errors were encountered: