make_cols_long | R Documentation |
This is a complex function that accepts specified lists of columns and melts them
into a long format from a wide format. This is designed for those columns in the original
NSQIP dataset that are stored in a wide format, such as the CPT, readmission and
reoperation columns; this is not meant for columns that store data in a comma-separated
fashion (such as anesthes_other
).
make_cols_long(
df,
...,
variable.name,
na.cols,
removeFALSE,
reorder = FALSE,
fn
)
df |
a data.table containing the columns in a wide format |
... |
character vectors of column names that will be melted together into single columns. |
variable.name |
desired output variable name; this is typically the numbering variable (optional) |
na.cols |
character vector of column names indicating which records should be removed when NA values are present in these columns (optional). |
removeFALSE |
character vector of a column name indicating which records should be removed when FALSE values are present in this column (optional). |
reorder |
logical vector indicating whether records should be reordered after removal
of NA and/or FALSE records. Will reorder the |
fn |
a function that can be used for processing the dataset after melting (optional). |
The ...
parameter accepts multiple character vectors that should each contain
the names of columns that will be melted together to create a single column in the long format
output. For example, a character vector named "reoperation" will contain the names "reoperation1",
"reoperation2", and "reoperation3", indicating these three columns in the original dataset will
be melted into a single column called "reoperation" in the long format.
The removeFALSE
character vector should only specify a single logical column.
The fn
parameter allows an anonymous function to be passed that operates on the melted
data frame. It applies this function prior to any NA or FALSE columns have been removed and
before the variable.name
has been reordered (if desired).
data.table
make_commas_long
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.