-
Notifications
You must be signed in to change notification settings - Fork 978
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
nafill, setnafill for character, factor and other types #3992
Comments
Maybe as a temp workaround:
and using mik3y64 example
|
Thanks @mik3y64 for the request. It is on the list to do, it was just not the part of the initial functionality. We have to first finish #3765 then the logic here can re-use changes from that PR. |
This comment has been minimized.
This comment has been minimized.
I agree that character support would be useful. Right now here is a workaround: library(data.table)
DT=data.table(x.chr=c("foo", NA, "bar"))
DT[, x.fac := factor(x.chr)]
DT[, x.int := as.integer(x.fac)]
setnafill(DT, type="locf", cols="x.int")
levs <- levels(DT$x.fac)
DT[, x.fac2 := factor(x.int, seq_along(levs), levs)]
DT[, x.chr2 := paste(x.fac2)] |
Extending @tdhock's approach to many character columns:
@jangorecki we don't need #4491 to do That would take out a lot of the work of the above... |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I filled #4980 that implements requested functionality. Still WIP. |
* nafill rework for more robust coerce * initial change for #4101 * nafill simple fill coerce * nafill const works for locf and nocb as well, closes #3594 * fix tests for #4101 * coverage * placeholder for nafill #3992 * use coerceAs in froll * enable disabled test * nafill retain names, tests for fill list * coerceAs gets copyArg so now can return its input * better control of verbose, and better find class for coerceAs * proper verbose to int * verbose changes coverage * rm unused anymore * more precise verbose arg check * memrecycle escape warnings and simple verbose for numcol==0 * coerceAs does not emit extra warning anymore * coerceAs verbose, more tests * use older nanotime api * update error msg * coverage * codecov of coerceAs * catch all verbose * Revert "initial change for #4101" This reverts commit 1fa2069. * Revert "fix tests for #4101" This reverts commit cc2cc0e. * use coerceAs in fcast.c * restore actual fix * ws * incomplete merge * vestigial bad merge * minimize diff * coerceAs throws warning for string->double, and errors on list * comment * example without warning * bad NEWS merge * warning is still needed --------- Co-authored-by: jangorecki <j.gorecki@wit.edu.pl> Co-authored-by: Michael Chirico <michael.chirico@grabtaxi.com>
nafill
andsetnafill
only supports numeric types.Both
zoo::na.locf
andtidyr::fill
support all data types.Feature request for supporting character, factor and other types. It's useful in many cases in merging and cleaning data.tables/data.frames. Unlike matrix, data.frames/data.tables usually contain columns of arbitrary types, and it's very common for data.tables/data.frames to have
NA
values filled in columns of arbitrary types, especially characters. Right now I have to import the specific functions from other packages just for that functionalities and those functions are much slower than the ones created bydata.table
.Thank you for creating this superior
data.table
package.The text was updated successfully, but these errors were encountered: