Skip to content
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

[R-Forge #5420] Implement 'margins' to dcast.data.table #531

Open
arunsrinivasan opened this issue Jun 8, 2014 · 3 comments
Open

[R-Forge #5420] Implement 'margins' to dcast.data.table #531

arunsrinivasan opened this issue Jun 8, 2014 · 3 comments

Comments

@arunsrinivasan
Copy link
Member

Submitted by: Arun ; Assigned to: Nobody; R-Forge link

The 'dcast' version of 'data.table' has everything implemented except for 'margins' argument.

@geneorama
Copy link

If this ever gets implemented, may I also suggest documenting the feature better than the original reshape2::dcast and adding examples.
This example from SO is pretty nice to show what it's supposed to look like (although I'm not sure what the merged result should look like): https://stackoverflow.com/questions/35167010/reshape2-dcast-margin-behavior
I like that this example switches the order of subject and treatment to show how the margins change.

Code example for posterity:

library('reshape2')
ff_d <- melt(french_fries, id=1:4, na.rm=TRUE)
a = dcast(ff_d, treatment + subject ~ variable, mean, margins=T)
b = dcast(ff_d, subject + treatment ~ variable, mean, margins=T)
d = merge(a, b, all = T) # I was expecting 'd' and 'a' (and 'b') to be identical.

This is one of those things that could be extremely useful for reporting, but it's probably not on many people's radars.

@vikasrawal
Copy link

Will this ever be implemented?

@jangorecki jangorecki added the reshape dcast melt label Jan 7, 2024
@jangorecki
Copy link
Member

dcast, when called with margins arg, could possibly just call grouping sets, which are computing exactly what margin arguments is about. The only missing piece AFAIR is that row totals are not part of the grouping sets, so that would have to be additionally handled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants