<p>Your issue seems to be related to the column <code>Position</code> being a character column in <code>a</code>, you should try:</p>

<pre class="lang-r prettyprint-override"><code>library(data.table)
a$Position &lt;- as.numeric(a$Position)
a[c, on = c("Chromosome","Position"), VAF := i.VAF]
</code></pre>

CC BY-SA 4.0
2020-01-09T14:25:50.377Z
2020-01-09T14:25:50.377Z
dc37
<p>I have two dataframes</p>

<pre><code>&gt; head(a[1:4,1:4])
   Tumor_Sample_Barcode Chromosome Position End_Position
1:                   A1       chr4 90169866     90169866
2:                   A1      chr11 60235747     60235747
3:                   A1       chr1   983023       983023
4:                   A1       chr1 11346060     11346060
&gt; 

&gt; head(c)
   Chromosome Position      VAF
1:       chrM     6691 0.610284
2:       chrM    14503 0.693325
3:       chr1 31412236 0.645161
4:       chr1 55693305 0.602941
5:       chr1 69963412 0.709302
6:       chr1 72608266 0.720000
&gt;

&gt; str(c)
Classes ‘data.table’ and 'data.frame':  44175 obs. of  3 variables:
 <span class="math-container">$ Chromosome: chr  "chrM" "chrM" "chr1" "chr1" ...
 $</span> Position  : num  6691 14503 31412236 55693305 69963412 ...
 $ VAF       : num  0.61 0.693 0.645 0.603 0.709 ...
 - attr(*, ".internal.selfref")=&lt;externalptr&gt; 
</code></pre>

<p>I want to merge them like this but complaining about not being integer</p>

<pre><code>&gt; a=a[c, on = c("Chromosome","Position"), VAF := i.VAF]
Error in bmerge(i, x, leftcols, rightcols, roll, rollends, nomatch, mult,  : 
  Incompatible join types: x.Position (character) and i.Position (integer)
</code></pre>

<p>I have tried something like these but not working</p>

<pre><code>&gt; c=c[!is.na(as.numeric(as.character(c<span class="math-container">$Position))), ]
&gt; 
&gt; c=c[!is.na(as.numeric(as.character(c$</span>VAF))), ]
&gt; 
&gt; c<span class="math-container">$VAF &lt;- as.numeric(as.character(c$</span>VAF)) 

c<span class="math-container">$Position &lt;- as.numeric(as.character(c$</span>Position)) 
</code></pre>

<p>which not working</p>

CC BY-SA 4.0
2020-01-09T13:25:34.233Z
Please add output of `str(head(a[1:4,1:4]))`
zx8754
CC BY-SA 4.0
2020-01-09T17:08:18.373Z
This type error is the same you had here : [Merging files gives memory allocation error](https://bioinformatics.stackexchange.com/questions/11000/merging-files-gives-memory-allocation-error). As I wrote in comment, updating the type of one data.table column is done this way :  `c[, position := as.integer(position)]`
Paul Endymion
<r>
Making some columns if a dataframe numeric
# Making some columns if a dataframe numeric

(Asked by: username_0 on 2020-01-09)

I have two dataframes
> head(a[1:4,1:4])
   Tumor_Sample_Barcode Chromosome Position End_Position
1:                   A1       chr4 90169866     90169866
2:                   A1      chr11 60235747     60235747
3:                   A1       chr1   983023       983023
4:                   A1       chr1 11346060     11346060
> 

> head(c)
   Chromosome Position      VAF
1:       chrM     6691 0.610284
2:       chrM    14503 0.693325
3:       chr1 31412236 0.645161
4:       chr1 55693305 0.602941
5:       chr1 69963412 0.709302
6:       chr1 72608266 0.720000
>

> str(c)
Classes ‘data.table’ and 'data.frame':  44175 obs. of  3 variables:
 $ Chromosome: chr  "chrM" "chrM" "chr1" "chr1" ...
 $ Position  : num  6691 14503 31412236 55693305 69963412 ...
 $ VAF       : num  0.61 0.693 0.645 0.603 0.709 ...
 - attr(*, ".internal.selfref")= 

I want to merge them like this but complaining about not being integer
> a=a[c, on = c("Chromosome","Position"), VAF := i.VAF]
Error in bmerge(i, x, leftcols, rightcols, roll, rollends, nomatch, mult,  : 
  Incompatible join types: x.Position (character) and i.Position (integer)

I have tried something like these but not working
> c=c[!is.na(as.numeric(as.character(c$Position))), ]
> 
> c=c[!is.na(as.numeric(as.character(c$VAF))), ]
> 
> c$VAF <- as.numeric(as.character(c$VAF)) 

c$Position <- as.numeric(as.character(c$Position)) 

which not working

**Tags:** r
> **Comments:**
> **username_1**: Please add output of `str(head(a[1:4,1:4]))`  
> **username_2**: This type error is the same you had here : [Merging files gives memory allocation error](https://bioinformatics.stackexchange.com/questions/11000/merging-files-gives-memory-allocation-error). As I wrote in comment, updating the type of one data.table column is done this way :  `c[, position := as.integer(position)]`  

---

## 1 answers

### Answer by username_3 on 2020-01-09. Score: 2 | Accepted answer

Your issue seems to be related to the column Position being a character column in a, you should try:
library(data.table)
a$Position <- as.numeric(a$Position)
a[c, on = c("Chromosome","Position"), VAF := i.VAF]


---

