How to join two new numeric columns in a dataframe using a separator?
<p>I have the dataframe df: </p>

<pre><code>start   end
836 845
3341    3350
4647    4661
4932    4942
10088   10098
13679   13690
16888   16954
20202   20225
</code></pre>

<p>Now I need a third column "JoinedCol" as</p>

<pre><code>836:845
3341:3350
4647:4661
4932:4942
10088:10098
...
...
</code></pre>

<p>I don't want to use paste() as it is producing column with char-type or factor. I want to use the new column "JoinedCol" to use in R for getting the data like </p>

<pre><code>836, 837,838,...844,845,3341,3342........ ..... 10098
</code></pre>

<p>As far as I know, you can't have this type of data in R.
If you join the ':' symbol to any number, the new string will always be a factor, a character or a matrix.</p>

<p>To retrieve data from that specific column you would have to specify which part you want, lets say with <code>substring()</code>. Otherwise you have to have both numbers in different columns, just as you original dataframe is.</p>

<hr>

<p>Still, you can have your data using the new JoinedCol:</p>

<pre><code>&gt;DF$JoinedCol=paste(DF$start,DF$end, sep=":") #Create the new column as you say

DF
  start   end  JoinedCol
1   836 10088  836:10088
2   845 10098  845:10098
3  3341 13679 3341:13679
4  3350 13690 3350:13690
5  4647 16888 4647:16888
6  4661 16954 4661:16954
7  4932 20202 4932:20202
8  4942 20225 4942:20225
</code></pre>

<hr>

<pre><code>&gt;substring(DF$JoinedCol,1,((regexpr(":", DF$JoinedCol))-1)) #To get first set of numbers (before the ':')

[1] "836"  "845"  "3341" "3350" "4647" "4661" "4932" "4942"
</code></pre>

<hr>

<pre><code>&gt;substring(DF$JoinedCol,(regexpr(":", DF$JoinedCol))+1,nchar(DF$JoinedCol)) #To get second set of numbers (after the ':')

[1] "10088" "10098" "13679" "13690" "16888" "16954" "20202" "20225"
</code></pre>

python