# Setting NA by case\_when function

**URL:** <https://community.exploratory.io/t/setting-na-by-case-when-function/971>\
**Category:** HowTo\
**Created:** [February 8, 2018, 4:34pm UTC](https://community.exploratory.io/t/setting-na-by-case-when-function/971 "2018-02-08T16:34:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hideaki\_Hayashi](https://community.exploratory.io/user_avatar/community.exploratory.io/hideaki_hayashi/32/10_2.png) [@Hideaki\_Hayashi](https://community.exploratory.io/u/Hideaki_Hayashi)\
**Post date:** [February 8, 2018, 4:34pm UTC](https://community.exploratory.io/t/setting-na-by-case-when-function/971/1 "2018-02-08T16:34:15Z")

</div>

Sometimes, you might want to use NA as one of the variables to convert some values into by case\_when function like this sceeenshot.

 ![](https://community.exploratory.io/uploads/default/original/1X/a3bcc7a74dd8f481ac8f021e5f2ade6916466dbf.png)

But unfortunately, it would fail with this kind of error. Basically, R doesn’t like that the NA does not have the same type as the other values set by case\_when function.

 ![](https://community.exploratory.io/uploads/default/original/1X/44662ba30a9c64a4755fb2770da5c60eb6cda469.png)

This can be worked around by using NA\_character\_ etc., which is NA with specific type.

 ![](https://community.exploratory.io/uploads/default/original/1X/5176e1120d19228166ebc8a9e6a9db7fdfbf1259.png)

 ![](https://community.exploratory.io/uploads/default/original/1X/52a168bd7eb68a37703a25458729e2a0cc25fed4.png)

There are also NA\_integer\_, NA\_real\_, NA\_complex\_, when you need to do this for other types of data.  
For more detail take a look at [the doc on NA](https://stat.ethz.ch/R-manual/R-devel/library/base/html/NA.html).
