यहां एक समाधान है और मैं इस पर कैसे पहुंचा।
group_by क्या अपेक्षा करता है?
> dplyr:::named_dots
function (...)
{
auto_name(dots(...))
}
<environment: namespace:dplyr>
> dplyr:::auto_name
function (x)
{
names(x) <- auto_names(x)
x
}
<environment: namespace:dplyr>
> dplyr:::auto_names
function (x)
{
nms <- names2(x)
missing <- nms == ""
if (all(!missing))
return(nms)
deparse2 <- function(x) paste(deparse(x, 500L), collapse = "")
defaults <- vapply(x[missing], deparse2, character(1), USE.NAMES = FALSE)
nms[missing] <- defaults
nms
}
<environment: namespace:dplyr>
> dplyr:::names2
function (x)
{
names(x) %||% rep("", length(x))
}
कि जानकारी, कैसे एक समाधान क्राफ्टिंग के बारे में जाने के लिए उपयोग करते हुए:
> group_by
function (x, ..., add = FALSE)
{
new_groups <- named_dots(...)
नीचे खरगोश की मांद
?
# Naive solution fails:
ChickWeight %>% do.call(group_by, list(Chick, Diet)) %>% summarise(mw = mean(weight))
# Slightly cleverer:
do.call(group_by, list(x = ChickWeight, Chick, Diet, add = FALSE)) %>% summarise(mw = mean(weight))
## But still fails with,
## Error in do.call(group_by, list(x = ChickWeight, Chick, Diet, add = FALSE)) : object 'Chick' not found
समाधान तर्क के हवाले से तो उनके मूल्यांकन देरी हो रही है में निहित है, जब तक वे वातावरण है कि x
tbl शामिल में कर रहे हैं:
do.call(group_by, list(x = ChickWeight, quote(Chick), quote(Diet), add = FALSE)) %>% summarise(mw = mean(weight))
## Bingo!
v <- "Diet"
do.call(group_by, list(x = ChickWeight, quote(Chick), substitute(a, list(a = v)), add = FALSE)) %>% summarise(mw = mean(weight))
:-) 'संक्षेप [एसआईसी] '+1 –
बस' group_by_ (सी (" चिक ", v) के बजाय 'group_by_ (c (" चिक ", v))' ' –
@Ari यदि आप अमेरिकी वर्तनी का उपयोग करते हैं, तो आप कोड में 'सारांश' का उपयोग क्यों करते हैं? –