Changing factor levels

Hello,

I’m trying to recode factors. I have been successful in changing variables from 0/1 to 1/2, for example, but when I try an alphanumeric name (e.g. “no” / “yes”) using ds.recodeValues I get the following warning:

 Warning message:
 'ds.recodeLevels' is deprecated.
 Use 'ds.recodeValues' instead.
 See help("Deprecated")

However, it does work. And when I use ds.recodeValues, it doesn’t. Any thoughts?

Hi Andrei,

You have to convert the factor to numeric using the ds.asNumeric function and then use the ds.recodeValues function to recode numbers to characters.

For the version that we are developing now (version 6.2), I rewrote the ds.recodeValues and that new version deals better with different types of variables (so for the new version, the conversion of a factor to numeric is not necessary).

I forgot to say that following the above steps, the recoded variable will be of class “character” but you can convert it back to a factor if you want using the ds.asFactor function.

Hey Demetris, thanks for all your advice (as ever!)