genderMaleFemale: Male and Female Response Option

Description Usage Arguments Value Author(s) Examples

Description

Gives "male" and "female" response option labels to variables.

Usage

1
genderMaleFemale(dat, vars, ros, ord=FALSE)

Arguments

dat

the data frame

vars

a single variable or a list of multiple variables

ros

0 denotes that the values are 0 (male) and 1 (female); 1 denotes that the values are 1 (male) and 2 (female)

ord

logical indicating whether the items should be ordinal (TRUE) or factor (FALSE:Default)

Value

This function will return response option labels for factors.

Author(s)

Seth Berry, Michael Clark

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--  or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function(dat, vars, ros, ord=FALSE){
  require(dplyr)
  datReduced = select(dat, one_of(vars))
  if(ros == 0)
    likOrd = lapply(datReduced, function(x)
      factor(x,
             levels = c(0,1),
             labels = c("male", "female"),
             ordered=ord)
    )
  else {
    datReduced = select(dat, one_of(vars))
    likOrd = lapply(datReduced, function(x)
      factor(x,
             levels = c(1,2),
             labels = c("male", "female"),
             ordered=ord)
    )  
  }
  likOrd = as.data.frame(likOrd)
  dat[,vars] = likOrd
}

saberry/lkrt documentation built on May 7, 2019, 2:32 p.m.