title: convert factor to date in R to create dummy variable
body: <p>I need to create dummy variable for &quot;before and after 04/11/2020&quot; for variable &quot;date&quot; in dataset &quot;counties&quot;. There are over hundred dates in the dataset. I am trying to covert the dates from factor to date with as.date function, but get NA. Could you please help finding where I am making an error? I kept the other dummy variable I created just in case, if it affects the overall outcome</p>
  <pre><code>counties &lt;- read.csv('C:/Users/matpo/Desktop/us-counties.csv')
  str(counties)
  as.Date(counties$date, format = '%m/%d/%y')
  #create dummy variables forNew York, New Jersey, California, and Illinois
  counties$state = ifelse(counties$state == 'New Jersey' &amp; 
                 counties$state == 'New York'&amp; counties$state == 'California' &amp; 
                 counties$state == 'Illinois', 1, 0)
  counties$date = ifelse(counties$date &gt;= &quot;4/11/2020&quot;, 1, 0)
  </code></pre>
  <p>str output</p>
  <pre><code> $ date  : logi  NA NA NA NA NA NA ...
   $ county: Factor w/ 1774 levels &quot;Abbeville&quot;,&quot;Acadia&quot;,..: 1468 1468 1468 379 1468 1178 379 1468 979 942 ...
   $ state : num  0 0 0 0 0 0 0 0 0 0 ...
   $ fips  : int  53061 53061 53061 17031 53061 6059 17031 53061 4013 6037 ...
   $ cases : int  1 1 1 1 1 1 1 1 1 1 ...
   $ deaths: int  0 0 0 0 0 0 0 0 0 0 ...``
  </code></pre>
  <p>Thank you!</p>