Problem
You want to rename the levels in a factor.
Rename the new copy of the dimension to the desired name. Drag both the new and old dimension fields to the Columns or Rows shelf. Right-click the header that should not be displayed and select Show Header. To view these steps in action, see the video below. A discord bot to rename your server's members with random (german) generated names! - XroixHD/RenameX.
Solution
The easiest way is to use revalue()
or mapvalues()
from the plyr package:
Rename Xcel
If you don’t want to rely on plyr, you can do the following with R’s built-in functions.Note that these methods will modify x
directly; that is, you don’t have to save the result back into x
.
It’s possible to rename factor levels by name (without plyr), but keep in mind that this works only if ALL levels are present in the list; if any are not in the list, they will be replaced with NA
.
It’s also possible to use R’s string search-and-replace functions to rename factor levels. Note that the ^
and $
surrounding alpha
are there to ensure that the entire string matches. Without them, if there were a level named alphabet
, it would also match, and the replacement would be onebet
.
See also
Rename Xref
Rename Xfinity Network
Mapping values in a vector to new values works much the same. See ../Mapping vector values for more information.