Merge and change NA separately in R
<p>My goal is merging 2 data sets together but I need to keep track "NA", I need to "NA" when I merge df1 and df2, and "NA" of df1 assign something like 9999. The problem is my data have so many variables, it includes day, numeric, character..., so when I try to set "NA" of df1 by <code>df1[is.na(df1)] &lt;- 9999</code>, it works only numeric, there is any way I can approach my solution to have different NA seperately.</p>

<pre><code>df1 &lt;- data.frame(ID= c(1:10), 
              Value=c(3,NA,7,2:8),
              Group = c("A",NA,"C","D",NA,"B",NA,"C","D",NA))

df2 &lt;- data.frame(ID = c(5:14),Count =c(1:9,NA),
                  School = c("A",NA,"C","D",NA,"B","NA","C","D",NA))

df1[is.na(df1)] &lt;- 9999

data &lt;- merge(df1,df2,all = TRUE,by= "ID")

   ID Value Group Count School
1   1     3     A    NA   &lt;NA&gt;
2   2  9999  &lt;NA&gt;*   NA   &lt;NA&gt;
3   3     7     C    NA   &lt;NA&gt;
4   4     2     D    NA   &lt;NA&gt;
5   5     3  &lt;NA&gt;*    1      A
6   6     4     B     2   &lt;NA&gt;
7   7     5   &lt;NA&gt;*    3      C
8   8     6     C     4      D
9   9     7     D     5   &lt;NA&gt;
10 10     8  &lt;NA&gt;*     6      B
11 11    NA  &lt;NA&gt;     7     NA
12 12    NA  &lt;NA&gt;     8      C
13 13    NA  &lt;NA&gt;     9      D
14 14    NA  &lt;NA&gt;    NA   &lt;NA&gt;
</code></pre>

<p>The ones <code>*</code> suppose 9999 </p>