-
Notifications
You must be signed in to change notification settings - Fork 991
New issue
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? Sign in to your account
Expression of column names in by
: clarify the function of list and parentheses
#2391
Labels
Comments
Henrik-P
changed the title
Expression of column names in
Expression of column names in Sep 28, 2017
by
- clarify list requirement and the use of parentheses (in j
as well)by
- clarify the function of list and parentheses (in j
as well)
Henrik-P
changed the title
Expression of column names in
Expression of column names in Sep 28, 2017
by
- clarify the function of list and parentheses (in j
as well)by
: clarify the function of list and parentheses (in j
as well)
Henrik-P
changed the title
Expression of column names in
Expression of column names in Sep 28, 2017
by
: clarify the function of list and parentheses (in j
as well)by
: clarify the function of list and parentheses
There is nothing special about the
to give you the expanded functional form. |
I'm surprised by the name of the output in both cases of by (x then grp).
compare too by = foo(x)
the column will be named foo
…On Sep 29, 2017 3:24 AM, "Henrik-P" ***@***.***> wrote:
I'm slightly confused by the use of list (or not) in by.
From ?data.table:
by accepts a list() of expressions of column names
d <- data.table(x = 1:4, y = 2:5)
This might be nitpicking, but as long as you don't *name* your
expression, the list doesn't seem to be needed. Unnamed expression in by
works without list:
d[ , sum(y), by = x %% 2]
# x V1
# 1: 1 6
# 2: 0 8
Furthermore, just tried to wrap a named expression in *parentheses*, it
also works:
d[ , sum(y), by = (grp = x %% 2)]
# grp V1
# 1: 1 6
# 2: 0 8
I haven't found anything in the docs on the use of ( in by. The
description in Reference semantics
<https://cran.r-project.org/web/packages/data.table/vignettes/datatable-reference-semantics.html>,
"e) Multiple columns and :=", seems like something else.
------------------------------
While being confused by the parentheses anyway, I just tried them in j:
d[ , sum_y = sum(y), by = (grp = x %% 2)]
# Error, fine.
# wrap in parentheses -> no error, albeit naming of result fails
d[ , (sum_y = sum(y)), by = (grp = x %% 2)]
# grp V1
# 1: 1 6
# 2: 0 8
------------------------------
I suppose I should suggest some improvement of the docs, but first I want
to check that I haven't overlooked something obvious here. Most likely I
have.
Thanks for your great work!
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#2391>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AHQQdXrDuifNUn18s6k7u2k8qlZBgEhWks5sm_JdgaJpZM4Pnw3x>
.
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm slightly confused by the use of
list
(or not) inby
.From
?data.table
:This might be nitpicking, but as long as you don't name your expression, the
list
doesn't seem to be needed. Unnamed expression inby
works withoutlist
:Furthermore, wrappin a named expression in parentheses instead of
list
works:I haven't found anything in the docs on the use of
(
inby
. The description in Reference semantics, "e) Multiple columns and:=
", seems like something else.While being confused by the parentheses anyway, I just tried them in
j
:At this point, I suppose I should provide some constructive comments on the docs, but first I want to check that I haven't overlooked something obvious here. Most likely I have.
Thanks for your great work!
The text was updated successfully, but these errors were encountered: