#' Split a numeric variable into a number of bins and return a vector of bin numbers
#'
#' @param x Numeric variable
#' @param n number of bins to create
#' @param rev Reverse the order of the bin numbers
#' @param type An integer between 1 and 9 to select one of the quantile algorithms described in the help for the stats::quantile function
#'
#' @seealso See \link[stats]{quantile} for a description of the different algorithm types
#'
#' @examples
#' xtile(1:10, 5)
#' xtile(1:10, 5, rev = TRUE)
#' xtile(c(rep(1, 6), 7:10), 5)
#'
#' @export
xtile<-function(x,n=5,rev=FALSE,type=7){
if(!is.numeric(x)){
stop(paste0("The variable to bin must be of type {numeric} but is of type {",class(x)[1],"}"),call.=FALSE)
}elseif(n<1){
stop(paste0("The number of bins must be > 1 but is ",n),call.=FALSE)
}elseif(length(x)<n){
stop(paste("The number of bins to create is larger than\nthe number of data points. Perhaps you grouped the data before\ncalling the xtile function and the number of observations per\ngroup is too small"),call.=FALSE)
}elseif(type<1||type>9){
stop(paste("The value for type is",type,"but must be between 1 and 9"),call.=FALSE)
if(length(breaks)<2)stop(paste("Insufficient variation in x to construct",n,"breaks"),call.=FALSE)
bins<-.bincode(x,breaks,include.lowest=TRUE)
if(rev)as.integer((n+1)-bins)elsebins
}
#' Show all rows with duplicated values (not just the first or last)
#'
#' @details If an entire row is duplicated use "duplicated" to show only one of the duplicated rows. When using a subset of variables to establish uniqueness it may be of interest to show all rows that have (some) duplicate elements
#'
#' @param .tbl Data frame to add transformed variables to
#' @param ... Variables used to evaluate row uniqueness
#' @details Keep only a specific set of levels in a factor. By removing levels the base for comparison in, e.g., regression analysis, becomes the first level. To relabel the base use, for example, repl = 'other'
#' @param x Character or Factor
#' @param levs Set of levels to use
#' @param repl String (or NA) used to replace missing levels
#' Split a numeric variable into a number of bins and return a vector of bin numbers
#'
#' @param x Numeric variable
#' @param n number of bins to create
#' @param rev Reverse the order of the bin numbers
#' @param type An integer between 1 and 9 to select one of the quantile algorithms described in the help for the stats::quantile function
#'
#' @seealso See \link[stats]{quantile} for a description of the different algorithm types
#'
#' @examples
#' xtile(1:10, 5)
#' xtile(1:10, 5, rev = TRUE)
#' xtile(c(rep(1, 6), 7:10), 5)
#'
#' @export
xtile<-function(x,n=5,rev=FALSE,type=7){
if(!is.numeric(x)){
stop(paste0("The variable to bin must be of type {numeric} but is of type {",class(x)[1],"}"),call.=FALSE)
}elseif(n<1){
stop(paste0("The number of bins must be > 1 but is ",n),call.=FALSE)
}elseif(length(x)<n){
stop(paste("The number of bins to create is larger than\nthe number of data points. Perhaps you grouped the data before\ncalling the xtile function and the number of observations per\ngroup is too small"),call.=FALSE)
}elseif(type<1||type>9){
stop(paste("The value for type is",type,"but must be between 1 and 9"),call.=FALSE)
if(length(breaks)<2)stop(paste("Insufficient variation in x to construct",n,"breaks"),call.=FALSE)
bins<-.bincode(x,breaks,include.lowest=TRUE)
if(rev)as.integer((n+1)-bins)elsebins
}
#' Show all rows with duplicated values (not just the first or last)
#'
#' @details If an entire row is duplicated use "duplicated" to show only one of the duplicated rows. When using a subset of variables to establish uniqueness it may be of interest to show all rows that have (some) duplicate elements
#'
#' @param .tbl Data frame to add transformed variables to
#' @param ... Variables used to evaluate row uniqueness
#' @details Keep only a specific set of levels in a factor. By removing levels the base for comparison in, e.g., regression analysis, becomes the first level. To relabel the base use, for example, repl = 'other'
#' @param x Character or Factor
#' @param levs Set of levels to use
#' @param repl String (or NA) used to replace missing levels
showNotification(i18n$t("Failed to read the sheet list from the xlsx file. Please check if the file is corrupted or properly formatted "),type="error")