R/createSonar.R

#' Create Sonar dataset
#' 
#' \emph{UCI description}: " Each pattern is a set of 60 numbers in the range 0.0 to 1.0. Each number represents the energy within a particular frequency band, integrated over a certain period of time. The integration aperture for higher frequencies occur later in time, since these frequencies are transmitted later during the chirp. The label associated with each record contains the letter "R" if the object is a rock and "M" if it is a mine (metal cylinder)." 
#' 
#' \emph{Task:} formula(Label ~ .)
#' 
#' @inheritParams createDiabetes
#' @export
createSonar<-function(file=getfilepath("sonar.rds"),write=TRUE,read=TRUE) {
  # Check if the user forced the recreation of the datasets or whether the datafile is missing on disk
  if (!read | !file.exists(file)) {
    data<-fread("http://archive.ics.uci.edu/ml/machine-learning-databases/undocumented/connectionist-bench/sonar/sonar.all-data")
    
    setnames(data,colnames(data),c(paste0("Energy",1:60),"Label"))
    
    data$Label<-factor(data$Label,levels=c("M","R"),labels=c("Mine","Rock"))
    
    if (write) {
      saveRDS(data, file=file)
    }
  } else {
    data<-readRDS(file)
  }
  
  return(data)
}
jkrijthe/createdatasets documentation built on May 19, 2019, 12:44 p.m.