title: Omit NA values while pasting two column values together in R
body: <p>I have a dataframe called <code>dd2</code>. I need to paste the values in <code>Left.Gene.Symbols</code> and <code>Right.Gene.Symbols</code> which I can do by simply using code below, but I would not want NAs pasted along if there is missing values. I want it to look like in the <code>combination</code> column as shown in <code>result</code>. </p>
  
  <p>mycode</p>
  
  <pre><code>#to remove NAs
  dd2[dd2 == 'NA'] &lt;- NA
  #pasting values together
  result &lt;- cbind(dd2,combination = paste(dd2[,"Left.Gene.Symbols"],dd2[,"Right.Gene.Symbols"],sep="*"))
  </code></pre>
  
  <p>data</p>
  
  <pre><code>dd2&lt;- structure(c("AMLM12001KP", "AMLM12001KP", "AMLM12001KP", "AMLM12001KP", 
  "AMLM12001KP", "AK2", "HFM1", "HFM1", "HFM1", "HFM1", NA, "PPT", 
  NA, "GGT", NA), .Dim = c(5L, 3L), .Dimnames = list(NULL, c("customer_sample_id", 
  "Left.Gene.Symbols", "Right.Gene.Symbols")))
  </code></pre>
  
  <p>result</p>
  
  <pre><code>   customer_sample_id Left.Gene.Symbols Right.Gene.Symbols  combination
  [1,] "AMLM12001KP"      "AK2"             NA                    AK2*
  [2,] "AMLM12001KP"      "HFM1"           "PPT"                  HFM1*PPT
  [3,] "AMLM12001KP"      "HFM1"            NA                    HFM1*
  [4,] "AMLM12001KP"      "HFM1"           "GGT"                  HFM1*GGT
  [5,] "AMLM12001KP"      "HFM1"            NA                    HFM1* 
  </code></pre>