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;
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
add a comment |
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
add a comment |
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
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
r dplyr rlang nse
edited Sep 9 '18 at 15:44
PoGibas
17.8k154779
17.8k154779
asked Jul 8 '17 at 9:03
danilinaresdanilinares
4771417
4771417
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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))
add a comment |
Transform the character vector into a list of symbols and splice it in
df %>% group_by(!!! syms(group_by))
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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))
add a comment |
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))
add a comment |
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))
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))
answered Mar 8 at 10:54
MarekMarek
39.4k1274107
39.4k1274107
add a comment |
add a comment |
Transform the character vector into a list of symbols and splice it in
df %>% group_by(!!! syms(group_by))
add a comment |
Transform the character vector into a list of symbols and splice it in
df %>% group_by(!!! syms(group_by))
add a comment |
Transform the character vector into a list of symbols and splice it in
df %>% group_by(!!! syms(group_by))
Transform the character vector into a list of symbols and splice it in
df %>% group_by(!!! syms(group_by))
answered Jul 10 '17 at 8:40
lionellionel
3,1671721
3,1671721
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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