Learn R Programming

ez (version 1.3)

ezLev: Function to re-order the levels of a factor

Description

This function provides easy re-ordering of factors.

Usage

ezLev(
	x
	, new_order
)

Arguments

x
Factor vector to be re-ordered.
new_order
Character vector indicating the new order of levels.

Value

  • The re-ordered factor vector.

Details

See examples.

See Also

relevel

Examples

Run this code
#Read in the ANT data (see ?ANT).
data(ANT)

#show the levels of flanker
levels(ANT$flanker)

#reorder the levels of flanker
levels(ANT$flanker)
ANT$flanker = ezLev(
	x = ANT$flanker
	, new_order = c('Incongruent Flanker','Neutral Flanker','Congruent Flanker')
)
levels(ANT$flanker)

#alternatively, you can use the level number
levels(ANT$cue)
ANT$cue = ezLev(
	x = ANT$cue
	, new_order = c(4,3,2,1)
)
levels(ANT$cue)

Run the code above in your browser using DataLab