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?
to your account
I stumbled over this when I was rolling up sample size (.N) for different sets of grouping variables, including no grouping.
If using groupingsets with an unnamed expression in j which is "autonamed" (e.g. .N) and including an "ungrouped" grouping set, then an additional variable is created for the ungrouped set.
d <- data.table(x = c("a", "a", "b"))
# 1: a
# 2: a
# 3: b
With a "grouped" grouping set only, an unnamed expression with .N in j works: the result is autonamed N:
groupingsets(d, j = .N, by = "x", sets = list("x"))
# x N
# 1: a 2
# 2: b 1
However, when also including an "ungrouped" grouping set (character()), an additional column is generated for the ungrouped result:
groupingsets(d, j = .N, by = "x", sets = list("x", character()))
# x N V1
# 1: a 2 NA
# 2: b 1 NA
# 3: <NA> NA 3
With an ungrouped grouping set only, the N column is included despite it was only used for the grouped result in the previous example:
groupingsets(d, j = .N, by = "x", sets = list(character()))
# x N V1
# 1: <NA> NA 3
Similar examples with named expressions in j, like j = .(N = .N), works.
j = .(N = .N)
Additional (admittedly contrived) attempts with .GRP and .I in j give similar results. Thus, it seems like this behaviour may be related to autonaming.
The text was updated successfully, but these errors were encountered:
fix autonaaming issue in groupings sets for special symbols, closes #…
Successfully merging a pull request may close this issue.