Learn R Programming

ctrdata (version 1.15.2)

dfListExtractKey: Extract named element(s) from list(s) into long-format data frame

Description

(Deprecated, use dfTrials2Long and dfName2Value!) The function uses a name (key) to extract an element from a list in a data.frame such as obtained with dbGetFieldsIntoDf. This helps to simplify working with nested lists and with complex structures.

Usage

dfListExtractKey(df, list.key = list(c("endPoints.endPoint", "^title")))

Value

A data frame (or tibble, if tibble is loaded) in long format with columns name (identifying the full path in the data frame, "<list>.<key>"), _id (of the trial record), value (of name per _id), item (number of value of name per _id).

Arguments

df

A data frame (or tibble)

list.key

A list of pairs of list names and key names, where the list name corresponds to the name of a column in df that holds a list and the name of the key identifies the element to be extracted. See example.

Examples

Run this code

dbc <- nodbi::src_sqlite(
   dbname = system.file("extdata", "demo.sqlite", package = "ctrdata"),
   collection = "my_trials")

df <- dbGetFieldsIntoDf(
  fields = c(
    "endPoints.endPoint",
    "subjectDisposition.postAssignmentPeriods"),
  con = dbc)

suppressWarnings(
  dfListExtractKey(
    df = df,
    list.key = list(
        c("endPoints.endPoint",
          "^title"),
        c("subjectDisposition.postAssignmentPeriods",
          "arms.arm.type.value"))
))

Run the code above in your browser using DataLab