#'insertDiffLevCol
#' @param dfData a data.frame object. Note that this is not a character string but the data.frame object itself. The parameter passed to the function should be without quotes (" ").
#' @param dfColNameVec a character string or a vector of class character indicating the name(s) of the column(s) to be handled.
#' @param numBreaksVec a vector of class numeric containing the number of class divisions (or exact boundaries) that should be taken for each column in \code{dfColNameVec}. The length of the vector must be equal to the length of \code{dfColNameVec}.
#' @return insertDiffLevCol updates the data.frame object \code{dfData} by adding new columns containing factor classes corresponding to the entries in the respective columns specified by \code{dfColNameVec} of the original data.frame.
#' @description sinsertDiffLevCol takes as input a data.frame object (\code{dfData}), a vector containing column names (\code{dfColNameVec}) and a numeric vector (\code{numBreaksVec}) containing the number of class divisions for each column in \code{dfColNameVec} and inserts a new column in \code{dfData} for each column in \code{dfColNameVec} containing the factor classes corresponding to the entries in that column.
#' @examples
#' insertDiffLevCol(iris,"Sepal.Length",5)
#' insertDiffLevCol(iris,c("Sepal.Length","Sepal.Width"),c(4,5))
#' @export
insertDiffLevCol<-function(dfData,dfColNameVec,numBreaksVec)
{
name<-deparse(substitute(dfData))
for(i in 1:length(dfColNameVec))
{
column<-data.frame(convertToLevels(dfData[,dfColNameVec[i]],20,numBreaksVec[[i]]))
names(column)=paste(dfColNameVec[i],"F",sep="")
dfData<-as.data.frame(append(dfData,column,after=(loc.col(dfData,dfColNameVec[i])[,2])))
}
assign(name,dfData,envir=globalenv())
return(get(name))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.