TysonStanley / tidyfast

Fast and efficient alternatives to tidyr functions built on data.table #rdatatable #rstats
https://tysonbarrett.com/tidyfast/
187 stars 4 forks source link

dt_fill() should not drop columns #45

Closed lindeloev closed 3 years ago

lindeloev commented 3 years ago

I suggest that dt_fill() should return all columns, like tidyr::fill().

Example:

# mtcars with some NA's in cyl
df = mtcars[1:6, ]
df$cyl[c(2, 4, 6)] = NA
> tidyfast::dt_fill(df, cyl)
   cyl
1:   6
2:   6
3:   4
4:   4
5:   8
6:   8

is not identical to

> tidyr::fill(df, cyl)
                   mpg cyl disp  hp drat    wt  qsec vs am gear carb
Mazda RX4         21.0   6  160 110 3.90 2.620 16.46  0  1    4    4
Mazda RX4 Wag     21.0   6  160 110 3.90 2.875 17.02  0  1    4    4
Datsun 710        22.8   4  108  93 3.85 2.320 18.61  1  1    4    1
Hornet 4 Drive    21.4   4  258 110 3.08 3.215 19.44  1  0    3    1
Hornet Sportabout 18.7   8  360 175 3.15 3.440 17.02  0  0    3    2
Valiant           18.1   8  225 105 2.76 3.460 20.22  1  0    3    1
TysonStanley commented 3 years ago

I like this suggestion. Was overlooked in the initial development. Will have an update over the next few weeks.

TysonStanley commented 3 years ago

If you want this sooner, you can try a pull request. If you do, I can add you as a contributor to the package. Otherwise, I'll be working on this over the next few weeks.

lindeloev commented 3 years ago

Sounds great! I'm pressed for time, so can't do a pull request, unfortunately.