either_both: either_both function

View source: R/format.R

either_bothR Documentation

either_both function

Description

Takes two variables (or two vectors of variables) and returns a vector representing the 'or' or the 'and' of the combination of two variables and adds a custom suffix

Usage

either_both(
  x,
  y,
  data = NULL,
  either = TRUE,
  pos = 1,
  neg = 0,
  addtn = "_comb",
  usexnames = TRUE,
  rmv = "none"
)

Arguments

x

quoted variable names (e.g. "var1") or vector of quoted variable names in the dataset to be compared to y

y

quoted variable names (e.g. "var1") or vector of quoted variable names in the dataset to be compared to x. If x and y are vectors of variable names they must be the same length

data

the dataset that contains the variables in x and y

either

boolean determining if the function should operate by 'or' or 'and'. default is TRUE indicating that the function returns the positive value if either input variable is 'positive'. FALSE returns positive if both input variables are positive

pos

the value that indicates 'positive', 'affirmative', or 'yes'. default is '1' to be used wit binary 0/1 variables

neg

the value that indicates 'negative', or 'no'. default is '0' to be used wit binary 0/1 variables

addtn

suffix to add to the variable names. default is '_comb' indicating 'combined'. if 'usexnames'==FALSE then addtn will be the base variable name and the iteration number will be added to it (e.g. if addtn is 'combined' then we would get combined1, combined2, etc.)

usexnames

boolean determining if the x variables should be used as the base variable names for the new combined variables. default is TRUE. if FALSE addtn is used as the base and then iterated if needed

rmv

text to remove from variable names if usexnames is TRUE. for example if all variable names contained '_pre_' and we wanted that removed we could put it in this argument. default is 'none' indicating no text is to be removed

Examples

either_function()


clmacleod/highlandr documentation built on Oct. 11, 2023, 8:04 p.m.