R/to.labels-set.R

Defines functions `to.labels<-`

#' Give Labels to Factor
#'
#' @param x factor or numeric variable
#' @param value labels separated by colon
#'
#' @return factor variable with lables, the first lable will be treated as reference.
#' @export
#'
#' @examples
#' to.labels(x=mtcars$am) <- c('0:Female','1:Man')
`to.labels<-`<-function(x,value){
    levels=do::Replace0(value,':.*')
    labels=do::Replace0(value,'.*:')
    factor(x,levels = levels,labels = labels)
}

Try the fastStat package in your browser

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

fastStat documentation built on Jan. 13, 2021, 7:32 a.m.