R/find.resp.R

Defines functions find.resp

## ##########################################################
## Function to find the response variable in a give ndata set
## ##########################################################

find.resp <- function(data,
                      resp)
{
  
  if (missing(data)){
    stop("Argument 'object' contains no data.") 
  }else{  
      
    if(is.character(resp)){

      if(any(resp == names(data))){

        name.resp <- names(data[charmatch(resp, names(data))])
        resp      <- data[,charmatch(resp, names(data))]
        
      }else{
        stop("Argument 'resp' is not found in data.")
      }      
    }else{

      if(is.numeric(resp)){
        if(length(resp) == 1){
          if(resp <= as.numeric(ncol(data))){
            
            name.resp <- names(data)[resp]
            resp      <- data[,resp]
            
          }else stop("Argument 'resp' is not found in data.")
        }else stop("Argument 'resp' is not correctly given.")
      }
    }
  }
  
  return(list(resp      = resp,
              name.resp = name.resp))
  
}



 

Try the nonrandom package in your browser

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

nonrandom documentation built on May 29, 2017, 11:41 p.m.