# Note that output variable name now includes the function name, in order to with 4 more variables: Sepal.Length_max, Sepal.Width_max , #> Species Sepal.Length_min Sepal.Width_min Petal.Length_min Petal.Width_min For example: by_species %>% summarise_all(funs(min, max)) Some of the examples in the scoped summarise docs use summarise_all to apply multiple functions to multiple columns. Is the workaround a good way to go or am I in danger of getting into some bad habits?Īre there other tidyverse approaches recommended in this situation? But I'm not sure if the workaround is necessary and I've missed an easy step somewhere. This seems OK to me and was the approach I suggested as an answer to a recent question. report % select(Sepal.Length:Petal.Width) %>% imap_dfr(report) Each remaining column relates to an arbitrary summary function. The first column returned is the original tibble column name. My current workaround is to ditch summarise_at() completely and define a function which returns a one row tibble. Is there another tidyverse way I should do this? One downfall of this approach is the logical result for anyNA() is now coerced to numeric. This is where I wonder if I'm heading in the wrong direction. Summarise_at(vars(Sepal.Length:Petal.Width), funs(min, anyNA)) %>% Perhaps I should use gather and spread to get the desired output: iris %>% Unfortunately, the above result isn't tidy. #> Sepal.Length_anyNA Sepal.Width_anyNA Petal.Length_anyNA #> Sepal.Length_min Sepal.Width_min Petal.Length_min Petal.Width_min I can then extend the previous example to summarise multiple columns: iris %>% summarise_at(vars(Sepal.Length:Petal.Width), funs(min, anyNA)) Iris %>% summarise_at("Petal.Width", funs(min, anyNA)) using min() and anyNA()): library(tidyverse) In addition, the results should be contained in a 'tidy' tibble.įor example, I can summarise one column multiple ways (e.g. Hi tidyverse community, I am wondering if there is a recommended tidyverse workflow when you want to summarise multiple columns in a tibble using multiple arbitrary summary functions.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |