View source: R/multiple_entries.R
fhir_melt | R Documentation |
This function divides multiple entries in an indexed data frame as produced by fhir_crack()
into separate rows.
fhir_melt(
indexed_data_frame,
columns,
brackets = c("<", ">"),
sep = " ",
id_name = "resource_identifier",
all_columns = FALSE
)
indexed_data_frame |
A data.frame/data.table with indexed multiple entries. |
columns |
A character vector specifying the names of all columns that should be molten simultaneously. It is advisable to only melt columns simultaneously that belong to the same (repeating) attribute! |
brackets |
A character vector of length two, defining the brackets used for the indices. |
sep |
A character vector of length one defining the separator that was used when pasting together multiple entries in |
id_name |
A character vector of length one, the name of the column that will hold the identification of the origin of the new rows. |
all_columns |
Return all columns? Defaults to |
Every row containing values that consist of multiple entries on the variables specified by the argument columns
will be turned into multiple rows, one for each entry. Values on other variables will be repeated in all the new rows.
The new data.frame will contain only the molten variables (if all_cloumns = FALSE
) or all variables
(if all_columns = TRUE
) as well as an additional variable resource_identifier
that maps which rows came
from the same origin. The name of this column can be changed in the argument id_name
.
For a more detailed description on how to use this function please see the corresponding package vignette.
A data.frame/data.table where each entry from the variables in columns
appears in a separate row.
fhir_common_columns()
, fhir_rm_indices()
#unserialize example
bundles <- fhir_unserialize(bundles = example_bundles1)
#crack fhir resources
table_desc <- fhir_table_description(
resource = "Patient",
brackets = c("[", "]"),
sep = " "
)
df <- fhir_crack(bundles = bundles, design = table_desc)
#find all column names associated with attribute address
col_names <- fhir_common_columns(df, "address")
#original data frame
df
#only keep address columns
fhir_melt(
indexed_data_frame = df,
columns = col_names,
brackets = c("[", "]"),
sep = " "
)
#keep all columns
fhir_melt(indexed_data_frame = df, columns = col_names,
brackets = c("[","]"), sep = " ", all_columns = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.