Bugs in converting Categorical dataset to Transaction dataset in R
<p>I have been working on feature engineering and I have come up with following code to converted the categorical dataset into binary transaction dataset, but I am not able get desired output, only three columns get populated with one. Rest all remain zero.</p>

<p>Here's my code:</p>

<pre><code>`binarize&lt;-function(dataset,names){ 
  drops&lt;-NA
  colnames(dataset)&lt;- paste("{",names,"}:",sep = "")
  dataset&lt;-dataset[,!(names(dataset)%in%drops)]
  dataset$id = 1:nrow(dataset)
  xt&lt;-dataset %&gt;% mutate_each(funs(as.character))%&gt;% gather(key,values,starts_with("{"))
  xt$values &lt;- apply( xt[ , c("key","values") ] , 1 , paste , collapse = "" )
  xt&lt;-xt %&gt;% mutate(present = 1)%&gt;% spread(values,present,fill = 0) 
  xt&lt;-xt%&gt;% distinct(id)
  rmCols&lt;-c("id","key")
  xt&lt;-xt[,-which(names(xt) %in% rmCols)]
  return(xt)
}`
</code></pre>

<p>Can someone help me debug this? names in the argument is a character vector.</p>

<p>Thanks,
Prerit</p>