... should exclude anything mentioned in value.var
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 38/100
Research direction
Start by reproducing the issue's melt and dcast examples, focusing on how dcast interprets ... and value.var. Trace the dcast entry point and its handling of formula variables. Done means dcast(DT_m, ... ~ ., value.var = "X", fun.aggregate = sum) excludes X from the grouping columns and produces the intended aggregated wide result.
Written by the indexing model from the issue text.
Description
Consider:
set.seed(120)
DT <- data.table(V1 = sample(10))
DT[ , paste0("V", 2:20) := replicate(19, sample(10), simplify = FALSE)]
DT[ , paste0("X", 1:50) := replicate(50, rnorm(10), simplify = FALSE)]
DT_m <- melt(DT, measure.vars = patterns("^X"), value.name = "X")
I want to reshape DT_m back to being "wide". I want V1:20 to be as originally in DT, but to aggregate all of X1:50 by summing into a single column.
It seems the way to do this is:
dcast(DT_m, V1 + V2 + V3 + [...] + V20 ~ ., fun.aggregate = sum)
# V1 V2 .
#1 1 5 5.452721
#2 2 9 2.855705
#3 3 2 -1.775939
#4 4 6 7.033915
#5 5 1 -10.456389
#6 6 8 9.050576
#7 7 4 4.917982
#8 8 7 1.901975
#9 9 10 3.969899
#10 10 3 -1.367950
But obviously it's not optimal to need to type all the variables on the LHS. I thought that was the point of ..., but this doesn't work:
dcast(DT_m, ... ~ ., value.var = "X", fun.aggregate = sum)
... has included X, so the returned table is just DT_m (with X renamed to .).
- Dominant language
- R
- Stars
- 3.9k
- Forks
- 1.1k
- Avg merge
- 14h 4m
- Merged PRs (30d)
- 4
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Rdatatable/data.table
-
as.data.table() recurses without end on a survival::Surv object (or any data.frame carrying one) Open
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Rdatatable/data.table#7887 ·
-
consistency tests
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Rdatatable/data.table#7853 · 3 comments ·
-
internals
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Rdatatable/data.table#6938 · 1 comment ·
-
encoding fread
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Rdatatable/data.table#5179 · 8 comments ·
-
documentation programming
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Rdatatable/data.table#3199 · 3 comments ·
All issues in Rdatatable/data.table
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
r-lib/pkgdepends#485 · 3 comments ·
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
-
beginners blocker
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enviPathR OpenBuild Error Build OK Build Warning policies-accepted pre-review precheck-passed
Difficulty 1/5 Under an hour Newbie friendliness 84/100
Bioconductor/BiocContributions#207 · 6 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
datacarpentry/semester-biology#1255 ·