R/variable_view.R

Defines functions variable_view

Documented in variable_view

#' @name variable_view
#' @title Variable names with labels like in SPSS
#' 
#' @param data the lme model object.
#'
#' @details Example call: variable_view(acipair)
#' @export 
#'
variable_view <- function(data){
  my.list = list()
  
  for (i in names(data)){
    #if the label is numeric then it's a "labels"; if it's null then it has neither a label or labels
    label = (c(i, ifelse(is.numeric(attr(data[[as.name(i)]],"label")) | is.null(attr(data[[as.name(i)]],"label")), 
                         NA, 
                         attr(data[[as.name(i)]],"label"))))
    my.list[[i]] = label
  }
  
  attributes = data.frame(matrix(unlist(my.list),ncol = 2,byrow = TRUE)) 
  
  colnames(attributes)[1] <- "variable"
  colnames(attributes)[2] <- "label"
  
  return(attributes)
}
RandiLGarcia/dyadr documentation built on March 23, 2021, 3:33 a.m.