-
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
Selecting all numeric columns #497
Comments
Right, just noticed that
does work, which makes sense. |
There's no best way currently. I think it's going to be fairly hard to implement across backend types, but maybe I could add some generic methods for determining column types. |
The To keep all numeric columns: iris %>%
purrr::keep(is.numeric) %>%
head(2)
#> Sepal.Length Sepal.Width Petal.Length Petal.Width
#> 1 5.1 3.5 1.4 0.2
#> 2 4.9 3.0 1.4 0.2 To mutate all numeric columns with a single function: iris %>%
purrr::map_if(is.numeric, log) %>%
head(2)
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#> 1 1.629241 1.252763 0.3364722 -1.609438 setosa
#> 2 1.589235 1.098612 0.3364722 -1.609438 setosa |
This function is analogous to summarise_if() and mutate_if() Closes tidyverse#497, closes tidyverse#1569
This function is analogous to summarise_if() and mutate_if() Closes tidyverse#497, closes tidyverse#1569
Nice! select_if() worked perfectly. Thank you. |
What's the best way of doing it?
The following
works with the latest version of
magrittr
. However,throws
Error in lapply(X = X, FUN = FUN, ...) : object '.' not found
, even with the updated chain operator. Is this the expected behaviour?In general, what is the best way to filter columns by some boolean condition in
dplyr
? Would it be worth having another selection function (in addition tostarts_with
,ends_with
, etc.) acting directly on columns instead of column names? E.g. something along the lines ofThe text was updated successfully, but these errors were encountered: