exposure {mds}R Documentation

MD-PMS Exposure Data Frame

Description

Converts a data frame into a MD-PMS Exposure data frame.

Usage

exposure(
  data_frame,
  time,
  device_hierarchy,
  event_hierarchy = NULL,
  key = NULL,
  match_levels = NULL,
  count = NULL
)

Arguments

data_frame

The input data frame requiring components specified in the remaining arguments.

time

Character name of date variable in data_frame. Class must be Date, POSIXt, or character.

Example: "event_date"

device_hierarchy

Vector of character variable names representing the device hierarchy in data_frame. Vector ordering is lowest level first, most general level last.

Example: c("Version", "Device", "ProductLine")

event_hierarchy

Vector of character variable names representing the event hierarchy in data_frame. Vector ordering is most specific event category first, most broad event category last.

Example: c("Family", "Device", "ProductCode")

Default: NULL will not include any event hierarchy.

key

Character name of (uniquely identifying) primary key variable in data_frame. Class must be character or numeric.

Example: "key_ID"

Default: NULL will create a key variable.

match_levels

Vector of character variable names in data_frame representing additional grouping factors for exposure. Specified variables will be implicitly matched to equivalently named variables contained in the mds_de object class.

Example: c("Country", "Region")

Default: NULL will not include any additional grouping factors.

count

Character name of exposure count variable in data_frame. Class must be numeric.

Example: "Units Sold"

Default: NULL will assume each row represents one exposure.

Value

A standardized MD-PMS data frame of class mds_e. Rows are deduplicated. Attributes are as follows:

key

Original variable name for key

time

Original variable name for time

device_hierarchy

Vector of original variable names for device_hierarchy with converted variable names correspondingly named.

event_hierarchy

Vector of original variable names for event_hierarchy with converted variable names correspondingly named.

match_levels

Vector of variable names for grouping factors

count

Original variable name for count

Examples

# A barebones dataset
ex <- exposure(sales, "sales_month", "device_name")
# With more variables and variable types
ex <- exposure(
  data_frame=sales,
  time="sales_month",
  device_hierarchy="device_name",
  match_levels="region",
  count="sales_volume")


[Package mds version 0.3.2 Index]