Allow the argument type.convert
of tstrsplit
to accept a named list.
#5094
Labels
Milestone
type.convert
of tstrsplit
to accept a named list.
#5094
This is not really an issue but a feature request.
Sometimes when using the function
tstrsplit
, setting its argumenttype.convert
toFALSE
orTRUE
does not return the desired output. We may want some columns in the result to be of a different type.
Here is an illustrative example:
Spltting the variable
x
:Setting
type.convert
toTRUE
:All columns are of type character when
type.convert=FALSE
and when it is set toTRUE
, the columnsgender
, andcovidTest
are set to character while the columnpersonID
is set to integer. In practice, it is quite likely that the desired type forgender
andcovidTest
isfactor
while the desired type forpersonID
is to keep it as character (especially because removing leading zeros lead to IDs that are likely not valid).My suggestion is to allow the
type.convert
argument to accept a named list where the names are functions and the values (integer positions or column names) specify the columns to apply the functions on.Using the same example, we would obtain something like:
This idea is closely related to that of the built-in function
strcapture
, which allows to split a variable into several columns by extracting groups. But it is usually quite slow and typing the same thing several times (likefactor
below) makes it less attractive.Further, the conversion function name must start with the prefix as. (like
as.factor
, etc.).The text was updated successfully, but these errors were encountered: