Setting NA by case_when function

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

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.

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

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.