R/formodel.R

Defines functions formodel

Documented in formodel

#' Format tab generated by Chloe to be used for the models computation
#'
#' `formodel()` Return the metrics computed by Chloe in a way that others function of this package
#' can run the different models.
#'
#' This function is made to be used to generate a tab used after in results_lm(), results_gam(),results_MARS,
#'  results_ALL() and tab_for_model().
#' @param chloe Your tab of results produced by your analysis on Chloe
#'
#' @param dist Vector of scales you choosed in Chloe when you created the ascii whith Cloe
#' @param metrics Vector of metrics you choosed in Chloe when you created the ascii whith Cloe
#'
#' @return Return a tab containing the metrics computed by Chloe formated to be be used by others functions
#' of this package
#' @author Pierre-Gilles Lemasle <pg.lemasle@gmail.com>
#' @export
formodel=function(chloe,dist,metrics){
  metrics=metrics[rev(order(metrics))]

  temp=NULL
  for (i in metrics) {
    test=chloe[,c(1,2,3,grep(i, colnames(chloe)))]

    colnames(test)[4:ncol(test)]=gsub(paste("_",i,sep = ""), "", colnames(test)[4:ncol(test)])
    colnames(test)[4:ncol(test)]=gsub("w", "", colnames(test)[4:ncol(test)])
    test=cbind(test[,c(1,2,3)],test[,as.character(sort(as.integer(colnames(test)[4:ncol(test)])))])
    colnames(test)[4:ncol(test)]=sub("^", "w", colnames(test)[4:ncol(test)])
    test$Metric=i
    temp=rbind(temp,test)
    chloe=chloe[,-grep(i, colnames(chloe))]
  }
  temp$Metric=as.factor(temp$Metric)

  return(temp)

}
Pintademijote/multipack documentation built on Sept. 24, 2019, 7:54 a.m.