I am using the read.csv
function along with the colClasses
parameter for reading my csv file. What i want to achieve is that for all the colClasses
that are "factors" , I want to specify the order of the factors .i.e.
If the column "Liquid-type" has the following factors :- "Water' , "Juice" , "Soda" , "Alcohol" , i want to control the ordering of factors .lets say
Water = 3
Juice=1
Soda=2
Alcohol =0
So how can i control the order of factors in read.csv
?
Edit: Your comment below, formatted:
setClass("customFactor")
setAs("character", "customFactor", function(from) {SpecifyOrders(from)})
SpecifyOrders <- function(from) {
from<- factor(from, levels=c(new_order)) }