visit_extract: Extract field data from UK Biobank visit data

Description Usage Arguments Value Examples

Description

Extracts all instances/arrays of data for a UK Biobank field(s) in clean "long" format (NOTE: watch for type coercion of different data types). See https://biobank.ndph.ox.ac.uk/showcase/ to identify field codes. Wrapper for visit_fields() which extracts raw field data.

Usage

1
visit_extract(visit_data, fields, format = NULL)

Arguments

visit_data

Data frame/table with UK Biobank data.

fields

Vector of fields to extract e.g. 50 or c(50, 21002). Field name will be identified from UK Biobank schema. Alternatively, field names can be set using a named vector e.g. c("height" = 50, "weight" = 21002).

format

Format of output table (raw or source). Default is currently raw but will change to source in a future release.

Value

Data table with values of all instances/arrays for each field in "long" format. The following columns are provided:

eid

UK Biobank identifier.

date

Visit date.

field/variable

Field name (see below).

array

Provided if any fields have multiple arrays (more than one value recorded on the same date e.g repeated blood pressure).

value

Value recorded.

If format = "source", an additional column source = "ukbb" is added to indicate data was recorded by UK Biobank and the field column is renamed variable. This will be the default in a future release. Use format = "raw" to keep current format.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
## Not run: 
# Load data
data_path <- ""  # add path to your data
visit_data <- fread(data_path)

# Extract a field
visit_extract(visit_data, 50)

# Extract multiple fields
visit_extract(visit_data, c(50, 21002))

# Manually specify a field name
visit_extract(visit_data, c("height" = 50, 21002))

## End(Not run)

philipdarke/ukbbhelpr documentation built on Dec. 22, 2021, 7:49 a.m.