Skip to content

Instantly share code, notes, and snippets.

print("hello")
@mattmalin
mattmalin / reorder_factors.r
Created June 29, 2012 10:57
reordering factors
# example ordering of elements in a factor for use in a graph:
mock <- data.frame(
element = as.factor(c(rep("foo", 10), rep("bar", 10), rep("hello", 10))),
value = rnorm(30))
levels(mock$element)
# [1] "bar" "foo" "hello"
# defining custom order for the elements:
my_order <- as.character(c("hello", "foo", "bar"))