title: How to convert long to wide format for single column with multiple categorical values
body: <p>I have data that contains a column called "states" with multiple commas separated values as following</p>
  
  <pre><code>test &lt;- structure(list(states = c("WA", "SC", "IN", "IN", "WI", "NY",
  "CA, CO, CT, DE, FL, GA, IA, ID, IL, IN, LA, MD, MI, MT, NJ, NV, OH, PA, SC, TX, UT, VA, WA", 
  "CA, CO, DE, GA, IL, LA, MA, MD, MI, MO, NJ, NV, NY, PA, VA, TX, WA", 
  "LA, MS", "DC, MD, VA", "AL, GA, NC", "MN WI", "MN WI", "KS, OK, TX", 
  "KS, MO, OK, TX", "IN, MI, NY, OH, PA", "CO, NE", "CO", "CO, NE", 
  "AZ, CA, CO, NV, TX, WA", "AZ, CA, NV, TX, UT,WA", "AZ, CA, NV, TX, UT, WA", 
  "CA, CT, IL, WA", "AL, AZ, CA, IL, MI, MO, MT, NJ, NM, OH, OK, PA, TX, VA, WI", 
  "AL, NC, TX, VA", "IL, MO, NJ, OH", "AZ, CA, CO, MN", "CO, IA, KY, TX", 
  "CO, IA, KY, MI, NC, NE, OH, PA, TX", "AR, GA, NC, NM, OK", "AL &amp; WV", 
  "KY, MN, ND, OH,OR,PA", "KS", "AL, AR, AZ, CA, CT, DE, FL, GA, HI, IA, IL, IN, KS, KY, LA, MA, MD, MI, MN, MO, MS, NC, NE, NJ, NM, NY, OH, OK, OR, PA, RI, SC, TN, TX, UT, VA, WI", 
  "AR, CO, GA, IL, LA, MI, MN, MS, MT, NC, ND, NE, OH, PA, RI, SC, TX, WI", 
  "AL, AR, AZ, CA, CT, DE, FL, GA, HI, IA, IL, IN, KS, KY, LA, MA, MD, MI, MN, MO, MS, NC, NE, NJ, NM, NY, OH, OK, OR, PA, RI, SC, TN, TX, UT, VA, WI", 
  "AL, AR, AZ, CA, CT, DE, FL, GA, HI, IA, IL, IN, KS, KY, LA, MA, MD, MI, MN, MO, MS, NC, NE, NJ, NM, NY, OH, OK, OR, PA, RI, SC, TN, TX, UT, VA, WI", 
  "AL, AZ, FL, KS, MI, MN, MO, NC, OK, WI", "GA, SC", "CA, CO, FL, IL, KY, NJ, OH, TX, VA", 
  "AL, AZ, CA, FL, GA, NJ, NM, NV, OH, PA, TX, VA", "ALL 50 STATES", 
  "ALL 50 STATES", "ALL 50 STATES", "AL, AZ, FL, GA, MI, NJ, NY, OH, OR, PA, TX, UT"
  )), .Names = "states", row.names = c(NA, -45L), class = c("tbl_df", 
                                                              "tbl", "data.frame"))
  test
  </code></pre>
  
  <p>I would like to convert it to a format that has the each "state" as a column and a 1 indicating that states presence and zero otherwise.</p>
  
  <p>Thanks</p>