claimpivot | R Documentation |
Pivot a record into long format, keeping paired diagnosis and POA fields together in the new format.
claimpivot(
tbl,
idcols,
diagstem = "ICD_DGNS_CD",
poastem = "CLM_POA_IND_SW",
poahandle = poa_cms,
poaconv = TRUE,
nahandle = na.pass
)
tbl |
Table of data in wide format |
idcols |
Name of the columns used as identifiers. If more than one, they will
be joined into a single synthetic key called 'id' (using |
diagstem |
Character stem for the names of the diagnosis fields (default is
|
poastem |
Character stem for the names of the POA fields (default is
|
poahandle |
Function for converting strings in POA fields to POA indicators (see details). |
poaconv |
Flag indicating whether to convert POA values, or just leave them as-is. |
nahandle |
What to do with POA values that don't match either the true
or false strings. Default is to leave them as |
Often a record for which we want to find the comorbidities will be organized with one row per record, and the diagnoses and POA indicators as fields within the row. This function pivots such tables into a long format with one row per diagnosis, and fields for the identifier, diagnosis, and POA flag. (The difference between this and an ordinary pivot is the pairing of the diagnosis and POA fields.)
The diagnosis and POA fields are identified by a stem, followed by a number. For example, "ICD_DGNS_CD13" for the 13th diagnosis code and "CLM_POA_IND_SW13" for the corresponding POA flag. In the output, each diagnosis will be matched up with its POA, and the ID will be replicated for each row.
If the POA column is of type character, it will be converted to an integer 0/1
value. This behavior can be suppressed by setting poaconv
to FALSE
.
By default, the CMS convention of using 'Y' for true will be used, with all other
values deemed to be false.
Other conventions can be used by supplying a function as the poahandle
argument. Several such functions for commonly encountered conventions are built
in (poa_functions
), or a custom function can be supplied.
Entries that decode to neither true nor false will be assigned the value NA. Optionally,
the function can raise an error if this happens (pass na.fail
in the nahandle
parameter.) This checking will also catch diagnosis code
fields for which no corresponding POA code was passed.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.