Skip to content
Prev 244593 / 398502 Next

Reorder factor and address embedded escapes

Does the following help?

A = c("A\\nB", "C\\nD")
test <-data.frame(A)

#access levels directly to change names
levels(test$A) <- sub("\\\\n", "\n", levels(test$A))

#re-order levels of the factor
test$A <- relevel(test$A, "C\nD")
Rob James wrote: