title: R Most Frequent Factor (yes/No)
body: <p>I am new to R and working on my first dataset and hence these questions. if its very basic, my apologies. </p>
  
  <p>I have a dataframe(<code>Df</code>) with few columns (some intergers, some factors and few texts).</p>
  
  <p>The Factor variables(one for example:f1) all have True/False/NA values. I am trying to replace the missing values with the most frequent value. </p>
  
  <p>I know the most frequent values of each of these factor variables. I found them using <code>summary(Df)</code>. But, dont want to hard code or use too many lines of code.I come from database background and I am visualizing the dataframe as a table and this factor variable as a column. Maybe thats my problem!</p>
  
  <p>Following are the options I tried and why it didnt work:</p>
  
  <ol>
  <li><code>Df$f1[is.na(Df$D1)] &lt;- median(as.numeric(levels(Df$f1)),na.rm=TRUE)</code></li>
  </ol>
  
  <p>This didnt work since its throwing a <code>warning : NAs introduced by coercion</code>.</p>
  
  <ol start="2">
  <li>I tried to convert the factors into numeric using <code>as.numeric</code> and find median and recode. But it's converting most of it into <code>NA</code>s.</li>
  </ol>
  
  <p>Please help!</p>