-2
$\begingroup$

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")=<externalptr> 

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

$\endgroup$
2
  • 1
    $\begingroup$ Please add output of str(head(a[1:4,1:4])) $\endgroup$
    – zx8754
    Jan 9, 2020 at 13:25
  • $\begingroup$ This type error is the same you had here : 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)] $\endgroup$ Jan 9, 2020 at 17:08

1 Answer 1

2
$\begingroup$

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]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.