-
Notifications
You must be signed in to change notification settings - Fork 57
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
across() needs to ignore grouping vars #173
Comments
Translating to a You can see the translation printed with option
It's true that someone might turn this optimization off via See https://www.rdocumentation.org/packages/data.table/versions/1.13.6/topics/datatable.optimize |
Plus, translating to |
Actually, the way this is implemented is probably the best approach since the lapply(.SD) approach doesn't generalize well to an arbitrary number of functions. This is the closest multiple functions comes to working. This is optimized, which is good, but the colnames don't get pasted to function names: library(data.table)
mtcarsdt <- as.data.table(mtcars)
mtcarsdt[, c(lapply(.SD,mean),lapply(.SD,sum)), by="cyl",.SDcols=3:5]
#> cyl disp hp drat disp hp drat
#> 1: 6 183.3143 122.28571 3.585714 1283.2 856 25.10
#> 2: 4 105.1364 82.63636 4.070909 1156.5 909 44.78
#> 3: 8 353.1000 209.21429 3.229286 4943.4 2929 45.21 Created on 2021-01-30 by the reprex package (v0.3.0) This could be fixed by following it up with a complicated setnames statement, but it's not a good solution. In theory the following should result in column names such as mean.disp, etc but that doesn't even work because of how the lapply statements get substituted (turn on datatable.verbose to see the substitution). library(data.table)
mtcarsdt <- as.data.table(mtcars)
mtcarsdt[, c("mean"=lapply(.SD,mean),"sum"=lapply(.SD,sum)), by="cyl",.SDcols=3:5]
#> cyl disp hp drat disp hp drat
#> 1: 6 183.3143 122.28571 3.585714 1283.2 856 25.10
#> 2: 4 105.1364 82.63636 4.070909 1156.5 909 44.78
#> 3: 8 353.1000 209.21429 3.229286 4943.4 2929 45.21
#how it should work according to base R named concatenation of named lists
c(A=list(a=1:3,b=1:3),B=list(a=1:3,b=1:3))
#> $A.a
#> [1] 1 2 3
#>
#> $A.b
#> [1] 1 2 3
#>
#> $B.a
#> [1] 1 2 3
#>
#> $B.b
#> [1] 1 2 3 Created on 2021-01-30 by the reprex package (v0.3.0) Maybe someday these rowwise/colwise functions will get implemented... |
Yeah, I think the generality of |
Created on 2021-01-30 by the reprex package (v0.3.0.9001)
The text was updated successfully, but these errors were encountered: