title: Create a new column based on other column names and values
body: <p>I am trying to create a new column based on few other column names and their values in that data frame.</p>
  
  <p>The data looks something like this</p>
  
  <pre><code>user_id  Gender Age  Cate_Ch_Bot  Cate_Ch_Phy  Cate_Ch_Chem  Cate_Ch_Comp  Cate_Ch_Zoo
  0001      F     13      0              1           0              1              0
  0002      M     17      1              1           0              0              0
  0003      F     13      0              0           0              0              0
  0004      F     12      0              0           1              0              0
  0005      F     14      0              1           0              0              1
  0006      M     16      0              0           0              0              0
  </code></pre>
  
  <p>I need to create a category column, which will have all the categories that have the value of 1. If the user does not have a category then it be blank or NA.</p>
  
  <p>So the desired output will be:</p>
  
  <pre><code>user_id  Gender Age Cate_Ch_Bot Cate_Ch_Phy Cate_Ch_Chem Cate_Ch_Comp Cate_Ch_Zoo   Ch_Category
  0001      F     13      0            1            0           1           0         Phy:Comp
  0002      M     17      1            1            0           0           0         Bot:Phy
  0003      F     13      0            0            0           0           0         NA
  0004      F     12      0            0            1           0           0         Chem
  0005      F     14      0            1            0           0           1         Phy:Zoo
  0006      M     16      0            0            0           0           0         NA
  </code></pre>
  
  <p>I am trying to loop through the column names, but not sure how to do it correctly.</p>
  
  <pre><code>test$category = ""
  for (j in 1:dim(test)[1]){
    for (i in colnames(test[4:14])){
      name = colnames(test[i])   
      if (test[j,name] == 1){
        test$category[j] = paste(test$category[j], colnames(test[i]),sep=":")
      }
    }
  }
  </code></pre>
  
  <p>I would deeply appreciate any help in this regard.</p>