imaginer: Match Two Items, Select, and Document

Description Usage Arguments Value Examples

View source: R/padis_specific_functions.R

Description

This function matches two items (identified based on their stem, see match_ir), documents which of the two items had a value and not a missing value, and returns a data frame with two or all plus two colums (depending on return_complete_data), where the first columns are the original columns from data, and the last two colums are the origin of the value and the value itself.

Usage

1
2
imaginer(data, var_stem, return_complete_data = FALSE, end_pattern = c(".r",
  ".i"), code_pattern = c(1, 0), return_indicator = TRUE)

Arguments

data

The data frame that contains the variables

var_stem

The stem of the item, i.e. the character stringr that both items share. Passed on to match_ir

return_complete_data

Logical, if TRUE, then the complete data frame is returned along with the two new values

end_pattern

The end pattern to search for. Default is c(".r", ".i")

code_pattern

The code pattern to be used. Default is c(1, 0). This means that if a value originates from the .r-variable, it is documented with a 1, and if it originates from a .i-variable, it is documented with a 0 in the indicator variable. If both columns (.r and .i) contain a missing value for a person, this value will be coded as 999.

return_indiciator

Logical. Should the indicator variable be returned as well? Default is to TRUE. If set to FALSE, only the final, merged variable is returned

Value

A data frame with either 2 colums or all original columns and two additional columns.

Examples

1
2
3
4
5
6
data <- imaginer_example_data
imaginer(data, var_stem="PSP1.variable.", return_complete_data=TRUE)

## return without the indicator variable
imaginer(data, var_stem="PSP1.variable.", return_complete_data=TRUE,
return_indicator = FALSE)

kthorstmann/padis documentation built on May 24, 2019, 5:01 a.m.