moodymudskipper / tb

IN ~PROGRESS my own take on `[.data.frame`
0 stars 0 forks source link

`.fill` argument #24

Open moodymudskipper opened 4 years ago

moodymudskipper commented 4 years ago

it will behave like the replace argument of tidyr::replace_na() or the values_fill argument of pivot_wider().

if a single value is given, all NAs are replaced, if a list is given, or a selection, we replace the given variables.

moodymudskipper commented 4 years ago

or can we use a binary ? there ?

fish_encounters %tb>% .[`{station}` = seen ? 0, .by = "fish"]

This way we can use it also with at/if features :

iris %>% .[(?"^Sepal" = .?0]

will replace in all columns starting by Sepal the missing values by 0

We could use a simple %NA% operator in the latter case though, but ? is necessary for gather, unless we have an .expand param. Moreover ? has better precedence, but we'll have to deal with := for precedence.

moodymudskipper commented 4 years ago

done

moodymudskipper commented 4 years ago

Reopening to add a feature.

We can be more flexible and allow the value to be a function to be applied, or a dot expression. We should also support the "along" formula notation here.

This way we can have fill = locf, fill = list(a = nocb, b = mean(., na.rm = TRUE) ~ mygrp)

This way we can do advanced imputation easily.

maybe check MICE package to see if we can do more

moodymudskipper commented 4 years ago

to support dotted expression we'll need to introduce funs() which should return a list of quoted expression with a class, then check the calls before applying.