fhir_common_columns: Find common columns

View source: R/multiple_entries.R

fhir_common_columnsR Documentation

Find common columns

Description

This is a convenience function to find all column names in a data frame starting with the same string that can then be used for fhir_melt().

Usage

fhir_common_columns(data_frame, column_names_prefix)

Arguments

data_frame

A data.frame/data.table with automatically named columns as produced by fhir_crack().

column_names_prefix

A string containing the common prefix of the desired columns.

Details

It is intended for use on data frames with column names that have been automatically produced by fhir_design()/fhir_crack() and follow the form level1.level2.level3 such as name.given or code.coding.system. Note that this function will only work on column names following exactly this scheme.

The resulting character vector can be used for melting all columns belonging to the same attribute in an indexed data frame, see ?fhir_melt.

Value

A character vector with the names of all columns matching column_names_prefix.

See Also

fhir_melt(), fhir_rm_indices()

Examples

#unserialize example bundles
bundles <- fhir_unserialize(bundles = medication_bundles)

#crack Patient Resources
pats <- fhir_table_description(resource = "Patient")

df <- fhir_crack(bundles = bundles, design = pats)

#look at automatically generated names
names(df)

#extract all column names beginning with the string "name"
fhir_common_columns(data_frame = df, column_names_prefix = "name")

TPeschel/fhiR documentation built on Jan. 15, 2024, 9:53 p.m.