R/toNums.r

Defines functions toNums

#' @title toNums
#' @description Convert specific columns in data from to numerics
#' @author  [email protected]
#' @export
toNums<-function(x,cols,numerics=T) {
	for(i in 1:length(cols)) {
	if(is.factor(x[,cols[i]])) {
	if(numerics==F){
	x[,cols[i]]<-as.character(levels(x[,cols[i]])[x[,cols[i]]])
	}
	else {
	x[,cols[i]]<-as.numeric(levels(x[,cols[i]])[x[,cols[i]]])
	}
	}
	else {
	x[,cols[i]]<-as.numeric(x[,cols[i]])
	}
	}
	return(x)
}
AMCOOK/bio.eels documentation built on Nov. 22, 2018, 2:16 p.m.