# Changing factor levels

**URL:** <https://datashield.discourse.group/t/changing-factor-levels/428>\
**Category:** Analyst Support\
**Created:** [27 July 2021 15:16 UTC](https://datashield.discourse.group/t/changing-factor-levels/428 "2021-07-27T15:16:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![asm](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@asm](https://datashield.discourse.group/u/asm)\
**Post date:** [27 July 2021 15:16 UTC](https://datashield.discourse.group/t/changing-factor-levels/428/1 "2021-07-27T15:16:11Z")

</div>

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:

```auto
 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?

---

<div class="post-metadata">

**Author:** ![demetris.avraam](https://avatars.discourse-cdn.com/v4/letter/d/439d5e/32.png) [@demetris.avraam](https://datashield.discourse.group/u/demetris.avraam)\
**Post date:** [27 July 2021 18:59 UTC](https://datashield.discourse.group/t/changing-factor-levels/428/2 "2021-07-27T18:59:54Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![demetris.avraam](https://avatars.discourse-cdn.com/v4/letter/d/439d5e/32.png) [@demetris.avraam](https://datashield.discourse.group/u/demetris.avraam)\
**Post date:** [27 July 2021 19:03 UTC](https://datashield.discourse.group/t/changing-factor-levels/428/3 "2021-07-27T19:03:39Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![asm](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@asm](https://datashield.discourse.group/u/asm)\
**Post date:** [31 July 2021 12:11 UTC](https://datashield.discourse.group/t/changing-factor-levels/428/4 "2021-07-31T12:11:58Z")

</div>

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