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

special case percentage in combine #2272

Closed
pdeffebach opened this issue May 27, 2020 · 2 comments
Closed

special case percentage in combine #2272

pdeffebach opened this issue May 27, 2020 · 2 comments
Labels
Milestone

Comments

@pdeffebach
Copy link
Contributor

Currently combine special cases nrow to get the number of rows.

It's actually pretty hard to get the percentage of observations in a group when doing a combine operation. You have to do nrow before, then save that variable, then make a new nrow.

It might be worth considering adding something like

julia> df = DataFrame(
           sex = rand(["Man", "Woman", "Other"], 100), 
           race = rand(["White", "Black", "Other"], 100), 
           income = rand(100));

julia> combine(groupby(df, "race"), percentage)

be a shorthand for

N = nrow(parent(df))
n = nrow(sdf)
return n / N
@bkamins bkamins added this to the 1.x milestone May 27, 2020
@bkamins
Copy link
Member

bkamins commented Sep 15, 2020

Actually it is even harder than you think, as gdf can be subsetted, so your code is incorrect, it should rather be:

n = [nrow(sdf) for sdf in gdf]
return n ./ sum(n)

which is not only not easy to type but also tricky.

I think it is OK to add this at some point.

@bkamins
Copy link
Member

bkamins commented Dec 4, 2022

added :proprow

@bkamins bkamins closed this as completed Dec 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants