extract: extract form data

Description Usage Arguments Details Value

View source: R/load.R

Description

extract takes a list of (nested) questions in odk json format and extracts the corresponding data from an appropriately formatted data.frame

Usage

1

Arguments

df

a dataframe of questions created by fromJSON

dat

a dataframe containing all the question data for the questions

group

the current groups (NULL for the top level)

Details

This function is primarily used by load.svy, but can be used on its own to extract svq objects from an odk survey. Each row in the data.frame corresponds to a question or question group. If it is a group, its name is appended to the group vector and extract is called recursively on its children element.

For each question, a variable of the appropriate type is extracted from dat using the name element, the group vector to select the appropriate column(s). "select one" questions remain factors with levels converted to their labels (in English) and stored in the choices attribute of the variable. "select all that apply" questions are converted into logical matrices with one column for each choice (and wrapped in I() to prevent them from being broken by as.data.frame()) and the (English) labels for the choices stored in the choices attribute of the matrix. "decimal" and "integer" types are converted, if necessary, to numeric vectors, "date" and "today" types are converted to Date, "time" types to POSIXct, and all others to character vectors. Then group and all the remaining elements of the question are appended to the attributes of the variable.

Value

a (flattened) list of objects of type svq, one for each question in df.


mlgrm/svyr documentation built on May 11, 2017, 9:57 p.m.