# create an example data frame
yourdata <-
data.frame(
cat1 = c( 1 , 0 , 1 ) ,
cont1 = c( 0 , 1 , 0 ) ,
cat2 = c( 0 , 0 , 1 )
)
# if this doesn't work for you,
# please ?dput some example data in the future :)
# figure out which variables contain the word 'cat'
vars.to.order <- grep( 'cat' , names( yourdata ) )
# convert all of those columns to factor..
yourdata[ , vars.to.order ] <- lapply( yourdata[ , vars.to.order ], factor )
# ..and then to ordered factor
yourdata[ , vars.to.order ] <- lapply( yourdata[ , vars.to.order ], ordered
)
# confirm the results of the new data frame
class( yourdata ) # yourdata is a data frame..
sapply( yourdata , class ) # here's the class of each column
yourdata # here's the whole data set printed to the screen
[[alternative HTML version deleted]]