title: Assign values to matrix based on condition
body: <p>I want to create a matrix with 3 columns and many rows assigning 1 or 0 if the condition is satisfied.</p>
  
  <p>I have data stored in 3 variables</p>
  
  <pre><code> df1 &lt;- data.frame(names=c("A","B","C","D","E","F"))
   df2 &lt;- data.frame(names=c("A","B","C","F"))
   df3 &lt;- data.frame(names=c("E","F","H"))
  </code></pre>
  
  <p>output will be</p>
  
  <pre><code>     df1  df2 df3
    A  1    1   0
    B  1    1   0 
    C  1    1   0
    D  1    0   0
    E  1    1   1
    F  1    0   1
    H  0    0   1
  </code></pre>
  
  <p>In first row if A is present in dataset then I will assign 1 under each column and 0 if A not present in dataset</p>
  
  <p>Here is what I have tried</p>
  
  <pre><code> DF &lt;- rbind(df1,df2,df3)
   for (i in DF) { 
       for (j in 1:length(df1$names)) {
                if(i == df1$names[j]){
                      A3 &lt;-data.frame(paste0("",i),paste0(1),paste0(0),paste0(0))
                      names(A3) &lt;- NULL 
                }
                else{
                      A3 &lt;-data.frame(paste0("",i),paste0(0),paste0(0),paste0(0))
  
                }
    }
  }
  </code></pre>
  
  <p>I have written this code only for df1 but its very slow because I have more than 1500 rows in my orignal data set. What would be the fastest way to do it?</p>