R/ouinon.R

Defines functions yesnoph ouinonph

Documented in ouinonph yesnoph

#' Oui/Non
#' Reorganise les variables non/oui vers oui/non.
#' @param df Data.frame
#'
#' @return un data.frame
#' @export
ouinonph <- function(df){
  ldf <- length(df)
  for (i in 1:ldf){
    if(is.integer(df[,i])==F & is.numeric(df[,i])==F & length(levels(df[,i]))==2){
      if (levels(df[,i])[1]=="non" & levels(df[,i])[2]=="oui"){
        df[,i] <- as.factor(df[,i])
        df[,i] <- factor(df[,i],c("oui","non"))
      }
    }}
  return(df)
}

#' yes/no
#' Reorganise les variables no/yes vers yes/no.
#' @param df Data.frame
#'
#' @return un data.frame
#' @export
yesnoph <- function(df){
  ldf <- length(df)
  for (i in 1:ldf){
    if(is.integer(df[,i])==F & is.numeric(df[,i])==F & length(levels(df[,i]))==2){
      if (levels(df[,i])[1]=="no" & levels(df[,i])[2]=="yes"){
        df[,i] <- as.factor(df[,i])
        df[,i] <- factor(df[,i],c("yes","no"))
      }
    }}
  return(df)
}
philippemichel/thesisph documentation built on Dec. 22, 2020, 11:08 a.m.