R/vargroup.R

Defines functions vargroup

Documented in vargroup

#'  Variable Group Listing
#'
#' Creates a vector containing the column numbers in a dataset for a variable group. The variable group is provided in the form of a prefix (e.g. "statusinemployment") and a suffix (e.g. 1:10), building a variable list to be checked against the variable names in the dataset.
#'
#' @author Beat Hulliger, Juan Berdugo
#' @param prefix (mandatory) A base variable name which is part of a variable group.
#' @param suffix (mandatory) Vector of the suffixes considered.
#' @param data (mandatory) A dataframe containing the variables and observations to be analyzed.
#' @return Column numbers of variable group within the dataset.
#' @export

vargroup <- function(prefix,suffix,data)
{
  p <- length(suffix)
  varn <- character(p)
  for (j in 1:p)
  {
    varn[j] <- paste(prefix,suffix[j],sep="")
  }
  varnames<- names(data)
  varnames<- tolower(varnames)
  varj <- pmatch(tolower(varn),varnames)
  if (length(varj)<length(suffix)) cat(paste("Warning: not all variables match the dataset.\n"))
  return(varj)
}

Try the sdap package in your browser

Any scripts or data that you put into this service are public.

sdap documentation built on May 2, 2019, 6:52 p.m.