R/to.nums.r

#' @export

to.nums <- 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/FoodHabits documentation built on May 5, 2019, 11:34 a.m.