group_by by a vector of characters using tidy evaluation semantics The 2019 Stack Overflow Developer Survey Results Are Inselect and rename stored in variabledplyr issues when using group_by(multiple variables)Dplyr: how to group_by(all)dplyr bizarre ERROR: group_by()%>%summarise() outputs just one lineUsing pre-existing character vectors in quasiquotation of an expression with rlangTidy evaluation programming and ggplot2Tidy evaluation when column names are stored in stringsMutliple errors using dplyr: object not found and could not find functiontidy evaluation: invalid argument errorCorrect use of the group_by and summarise() functions?Conditional count and mean by grouped data without filter or left_join

If I score a critical hit on an 18 or higher, what are my chances of getting a critical hit if I roll 3d20?

What is this sharp, curved notch on my knife for?

Can a flute soloist sit?

Why does the nucleus not repel itself?

Geography at the pixel level

Why don't hard Brexiteers insist on a hard border to prevent illegal immigration after Brexit?

What is the light source in the black hole images?

For what reasons would an animal species NOT cross a *horizontal* land bridge?

Button changing its text & action. Good or terrible?

How much of the clove should I use when using big garlic heads?

"as much details as you can remember"

Old scifi movie from the 50s or 60s with men in solid red uniforms who interrogate a spy from the past

Does adding complexity mean a more secure cipher?

How did passengers keep warm on sail ships?

Why doesn't UInt have a toDouble()?

Cooking pasta in a water boiler

Does HR tell a hiring manager about salary negotiations?

Straighten subgroup lattice

Why doesn't shell automatically fix "useless use of cat"?

Is it ethical to upload a automatically generated paper to a non peer-reviewed site as part of a larger research?

Can we generate random numbers using irrational numbers like π and e?

Is one supposed to eat the zero'ah (shank bone) from the Seder plate?

Star Trek - X-shaped Item on Regula/Orbital Office Starbases

Is it possible for absolutely everyone to attain enlightenment?



group_by by a vector of characters using tidy evaluation semantics



The 2019 Stack Overflow Developer Survey Results Are Inselect and rename stored in variabledplyr issues when using group_by(multiple variables)Dplyr: how to group_by(all)dplyr bizarre ERROR: group_by()%>%summarise() outputs just one lineUsing pre-existing character vectors in quasiquotation of an expression with rlangTidy evaluation programming and ggplot2Tidy evaluation when column names are stored in stringsMutliple errors using dplyr: object not found and could not find functiontidy evaluation: invalid argument errorCorrect use of the group_by and summarise() functions?Conditional count and mean by grouped data without filter or left_join



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















I used to do it, using group_by_



library(dplyr)
group_by <- c('cyl', 'vs')
mtcars %>% group_by_(.dots = group_by) %>% summarise(gear = mean(gear))


but now group_by_ is deprecated. I don't know how to do it using the tidy evaluation framework.










share|improve this question






























    1















    I used to do it, using group_by_



    library(dplyr)
    group_by <- c('cyl', 'vs')
    mtcars %>% group_by_(.dots = group_by) %>% summarise(gear = mean(gear))


    but now group_by_ is deprecated. I don't know how to do it using the tidy evaluation framework.










    share|improve this question


























      1












      1








      1








      I used to do it, using group_by_



      library(dplyr)
      group_by <- c('cyl', 'vs')
      mtcars %>% group_by_(.dots = group_by) %>% summarise(gear = mean(gear))


      but now group_by_ is deprecated. I don't know how to do it using the tidy evaluation framework.










      share|improve this question
















      I used to do it, using group_by_



      library(dplyr)
      group_by <- c('cyl', 'vs')
      mtcars %>% group_by_(.dots = group_by) %>% summarise(gear = mean(gear))


      but now group_by_ is deprecated. I don't know how to do it using the tidy evaluation framework.







      r dplyr rlang nse






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Sep 9 '18 at 15:44









      PoGibas

      17.8k154779




      17.8k154779










      asked Jul 8 '17 at 9:03









      danilinaresdanilinares

      4771417




      4771417






















          2 Answers
          2






          active

          oldest

          votes


















          3














          There is group_by_at variant of group_by:



          library(dplyr)
          group_by <- c('cyl', 'vs')
          mtcars %>% group_by_at(group_by) %>% summarise(gear = mean(gear))


          Above it's simplified version of generalized:



          mtcars %>% group_by_at(vars(one_of(group_by))) %>% summarise(gear = mean(gear))


          inside vars you could use any dplyr way of select variables:



          mtcars %>%
          group_by_at(vars(
          one_of(group_by) # columns from predefined set
          ,starts_with("a") # add ones started with a
          ,-hp # but omit that one
          ,vs # this should be always include
          ,contains("_gr_") # and ones with string _gr_
          )) %>%
          summarise(gear = mean(gear))





          share|improve this answer






























            8














            Transform the character vector into a list of symbols and splice it in



            df %>% group_by(!!! syms(group_by))





            share|improve this answer























              Your Answer






              StackExchange.ifUsing("editor", function ()
              StackExchange.using("externalEditor", function ()
              StackExchange.using("snippets", function ()
              StackExchange.snippets.init();
              );
              );
              , "code-snippets");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "1"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f44984428%2fgroup-by-by-a-vector-of-characters-using-tidy-evaluation-semantics%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              3














              There is group_by_at variant of group_by:



              library(dplyr)
              group_by <- c('cyl', 'vs')
              mtcars %>% group_by_at(group_by) %>% summarise(gear = mean(gear))


              Above it's simplified version of generalized:



              mtcars %>% group_by_at(vars(one_of(group_by))) %>% summarise(gear = mean(gear))


              inside vars you could use any dplyr way of select variables:



              mtcars %>%
              group_by_at(vars(
              one_of(group_by) # columns from predefined set
              ,starts_with("a") # add ones started with a
              ,-hp # but omit that one
              ,vs # this should be always include
              ,contains("_gr_") # and ones with string _gr_
              )) %>%
              summarise(gear = mean(gear))





              share|improve this answer



























                3














                There is group_by_at variant of group_by:



                library(dplyr)
                group_by <- c('cyl', 'vs')
                mtcars %>% group_by_at(group_by) %>% summarise(gear = mean(gear))


                Above it's simplified version of generalized:



                mtcars %>% group_by_at(vars(one_of(group_by))) %>% summarise(gear = mean(gear))


                inside vars you could use any dplyr way of select variables:



                mtcars %>%
                group_by_at(vars(
                one_of(group_by) # columns from predefined set
                ,starts_with("a") # add ones started with a
                ,-hp # but omit that one
                ,vs # this should be always include
                ,contains("_gr_") # and ones with string _gr_
                )) %>%
                summarise(gear = mean(gear))





                share|improve this answer

























                  3












                  3








                  3







                  There is group_by_at variant of group_by:



                  library(dplyr)
                  group_by <- c('cyl', 'vs')
                  mtcars %>% group_by_at(group_by) %>% summarise(gear = mean(gear))


                  Above it's simplified version of generalized:



                  mtcars %>% group_by_at(vars(one_of(group_by))) %>% summarise(gear = mean(gear))


                  inside vars you could use any dplyr way of select variables:



                  mtcars %>%
                  group_by_at(vars(
                  one_of(group_by) # columns from predefined set
                  ,starts_with("a") # add ones started with a
                  ,-hp # but omit that one
                  ,vs # this should be always include
                  ,contains("_gr_") # and ones with string _gr_
                  )) %>%
                  summarise(gear = mean(gear))





                  share|improve this answer













                  There is group_by_at variant of group_by:



                  library(dplyr)
                  group_by <- c('cyl', 'vs')
                  mtcars %>% group_by_at(group_by) %>% summarise(gear = mean(gear))


                  Above it's simplified version of generalized:



                  mtcars %>% group_by_at(vars(one_of(group_by))) %>% summarise(gear = mean(gear))


                  inside vars you could use any dplyr way of select variables:



                  mtcars %>%
                  group_by_at(vars(
                  one_of(group_by) # columns from predefined set
                  ,starts_with("a") # add ones started with a
                  ,-hp # but omit that one
                  ,vs # this should be always include
                  ,contains("_gr_") # and ones with string _gr_
                  )) %>%
                  summarise(gear = mean(gear))






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 8 at 10:54









                  MarekMarek

                  39.4k1274107




                  39.4k1274107























                      8














                      Transform the character vector into a list of symbols and splice it in



                      df %>% group_by(!!! syms(group_by))





                      share|improve this answer



























                        8














                        Transform the character vector into a list of symbols and splice it in



                        df %>% group_by(!!! syms(group_by))





                        share|improve this answer

























                          8












                          8








                          8







                          Transform the character vector into a list of symbols and splice it in



                          df %>% group_by(!!! syms(group_by))





                          share|improve this answer













                          Transform the character vector into a list of symbols and splice it in



                          df %>% group_by(!!! syms(group_by))






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Jul 10 '17 at 8:40









                          lionellionel

                          3,1671721




                          3,1671721



























                              draft saved

                              draft discarded
















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f44984428%2fgroup-by-by-a-vector-of-characters-using-tidy-evaluation-semantics%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              AWS Lex not identifying response if by a variable The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceEnforcing custom enumeration in AWS LEX for slot valuesHow to give response based on user response in Amazon Lex?Intercepting AWS Lambda Response to a AWS Lex QueryLex chat bot error: Reached second execution of fulfillment lambda on the same utteranceamazon lex showing invalid responseLambda response send back to Lex slot?Response card in Amazon lexAmazon Lex - Lambda response return HTML to botHow can I solve 424 (Failed Dependency) (python) obtained from Amazon lex?

                              Алба-Юлія

                              Захаров Федір Захарович