title: merge the Boxes of interest of a data frame in a same column
body: <p>I'm a beginner in R. For my internship I need to make a new column of the unique non-NA value of each row of my a dataframe. The thing is this value is not always on the same column.</p>
  <p>I'm editing my post. Here is my code</p>
  <pre><code>wd&lt;-getwd()
  datapath&lt;-paste0(wd,&quot;/data/HSgeneAges.tab&quot;)
  feat&lt;-read.table(datapath,sep='\t',header = TRUE)
  feat&lt;-data.frame(feat[,c(2,3,4,9)])
  #creating a dataframe of 18 columns 
  #with colnames to be each unique value of column 4 of  feat dataframe
  geneage&lt;-data.frame(matrix(ncol=18,nrow=0))
  nomcol&lt;-unique(feat[,4])
  colnames(geneage)&lt;-nomcol
  
  for (i in 1:length(feat[,4])){  # as many rows as in feat
    for (j in 1:length(nomcol)){  # length is 18 ( number of columns of geneage)
      if (feat[i,4]==nomcol[j]){
        geneage[i,j]&lt;-j
      }
    }
  }
  #binding geneage and feat on commons columns 
  #and removing that column than make a file out of it
  geneage&lt;-cbind(feat,geneage)
  geneage&lt;-geneage[,-4]
  datapath&lt;-paste0(wd,&quot;/data/p.txt&quot;)
  write.table(geneage,datapath)
  </code></pre>
  <p><a href="https://i.stack.imgur.com/9OtP9.png" rel="nofollow noreferrer">Here is what the code produces so far</a> ( I can't show you all the row (21) as there are too many)</p>
  <p>And here is what I'dlike to have ( an example on the first 11 rows)</p>
  <pre><code>dput(df)
  structure(list(Chromosome = c(&quot;X&quot;, &quot;X&quot;, &quot;20&quot;, &quot;1&quot;, &quot;1&quot;, &quot;1&quot;, 
  &quot;1&quot;, &quot;6&quot;, &quot;6&quot;, &quot;6&quot;, &quot;1&quot;), Start = c(99883667L, 99839799L, 49551404L, 
  169818772L, 169631245L, 27938575L, 196621008L, 143815948L, 53362139L, 
  41040684L, 24683489L), End = c(99894988L, 99854882L, 49575092L, 
  169863408L, 169823221L, 27961788L, 196716634L, 143832827L, 53481768L, 
  41067715L, 24743424L), geneage = c(1, 1, 2, 3, 1, 1, 4, 1, 2, 
  2, 5)), class = &quot;data.frame&quot;, row.names = c(NA, 11L))
  </code></pre>
  <p>I hope to be clearer now.</p>
  <p>By the way if somenone knows of to avoid the loops I ager to know how!
  Alexis.</p>