Replace NULL in a dataframe
<p>I've the following dataframe:</p>

<pre><code>  freq.a freq.b              
1 NULL   0.055               
2 0.030  0.055              
3 0.060  0.161                    
4 0.303  0.111                   
5 0.393  0.111                   
6 0.121  0.388                   
7 0.090  0.111
</code></pre>

<p>And I would like to replace the <code>NULL</code> with an actual 0. However executing <code>df.m[is.null(df.m)] &lt;- 0</code> doesn't change anything in the dataframe. </p>

<p>MWE as follows(sorry for the length):</p>

<pre><code>library(plyr)
df.a &lt;- c(5, 4, 5, 7, 3, 5, 6, 5, 5, 4, 5, 5, 4, 5, 4, 7, 2, 4, 4, 5, 3, 6, 5, 6, 4, 4, 5, 4, 5, 5, 6, 7, 4)
df.b &lt;- c(1, 3, 4, 6, 2, 7, 7, 4, 3, 6, 6, 3, 6, 6, 5, 6, 6, 5)
df.a.count &lt;- count(df.a)
df.b.count &lt;- count(df.b)

#normalize the data
df.a.count$freq &lt;- lapply(df.a.count$freq, function(X) X/length(df.a))
df.b.count$freq &lt;- lapply(df.b.count$freq, function(X) X/length(df.b))
df.m &lt;- merge(df.a.count, df.b.count, by ='x', all=TRUE)[2:3]
names(df.m) &lt;- c('freq.a', 'freq.b')

#replace the NULL's with 0
df.m[is.null(df.m)] &lt;- 0
</code></pre>