|
Consider I'd like to create a function that just multiplies two column inputs. Edit: put the import statements in and changed the column inputs it's different than the |
Replies: 1 comment 3 replies
|
Sorry for the late response. I was off for a couple of days. This should be from datar import f
from datar.core.factory import func_factory
from datar.core.tibble import TibbleGrouped
from datar.dplyr import group_by, mutate
from datar.datasets import mtcars
# register the generic function
mymult = func_factory({"x", "w"}, kind="apply_df", func=lambda x, w: ...)
# .register() provides post hook
# The index of the result is problematic for mutate()
@mymult.register(TibbleGrouped, post=lambda out, x, w: out.reset_index(drop=True))
def mymult(x, w): # Ideally I could say w=1
return x * w
mtcars >> group_by(f.cyl) >> mutate(x = mymult(f.disp, f.hp))In the next major release, the confusion should be eliminated. Kinds Maybe we should separate kinds |
Sorry for the late response. I was off for a couple of days.
This should be
apply_dffor sure. So the solution will be: