good day, I had previously posted a question but it was too cumbersome and I overloaded it with data. Basically what I want to ask is that if there is any way to generate a dataset with match
or some other function that gives me all the matches, even repeated values, when comparing two or more lists and if possible, that this function does not remove the " NA
" of the result.
Example: I have this 2 frames
Frame 1 Frame 2
GenIDModel GenIDOrganisms GenIDModel GenIDOrganism1
gen_pep01 hsa_pep01 gen_pep01 hsa_pep01
gen_pep01 hsa_pep02 gen_pep01 hsa_pep02
gen_pep01 hsa_pep03 gen_pep01 hsa_pep03
gen_pep03 hsa_pep11 gen_pep03 hsa_pep11
gen_pep05 hsa_pep20 gen_pep05 hsa_pep20
gen_pep02 rno_pep14
gen_pep05 rno_pep22
gen_pep05 rno_pep23
gen_pep05 rno_pep25
gen_pep01 dre_pep01
gen_pep03 dre_pep08
gen_pep08 dre_pep99
gen_pep11 dre_pep99
gen_pep02 rno_pep24
gen_pep03 rno_pep35
gen_pep05 rno_pep20
gen_pep07 rno_pep27
When I use match
MatchFrame1vsFrame2 <- match(Frame1$GenIDModel, Frame2$GenIDModel)
I get this
MatchFrame1vsFrame2
# [1] 1 1 1 4 5 NA 5 5 5 1 4 NA NA NA 4 5 NA
And when I extract the names I get this
NamesMatchFrame1vsFrame2 <- Frame2$GenIDOrganism1[MatchFrame1vsFrame2]
NamesMatchFrame1vsFrame2
# [1] "hsa_pep01" "hsa_pep01" "hsa_pep01" "hsa_pep11" "hsa_pep20"
# [6] NA "hsa_pep20" "hsa_pep20" "hsa_pep20" "hsa_pep01"
# [11] "hsa_pep11" NA NA NA "hsa_pep11"
# [16] "hsa_pep20" NA
But what I actually want is this
# [1] "hsa_pep01" "hsa_pep02" "hsa_pep03" "hsa_pep11" "hsa_pep20"
# [6] NA "rno_pep22" "rno_pep23" "rno_pep25" "dre_pep01"
# [11] "dre_pep08" NA NA NA "rno_pep35"
# [16] "rno_pep20" NA
Is there any function or series of functions that allows me to obtain something like this?
Note:
I also tried with %in%
but when I extract the names it doesn't give me all of them
inFrame1vsFrame2 <- Frame1$GenIDModel %in% Frame2$GenIDModel
inFrame1vsFrame2
# [1] TRUE TRUE TRUE TRUE TRUE FALSE TRUE TRUE TRUE TRUE
# [11] TRUE FALSE FALSE FALSE TRUE TRUE FALSE
NamesinFrame1vsFrame2 <- Frame2$GenIDOrganism1[inFrame1vsFrame2]
NamesinFrame1vsFrame2
# [1] "gen_pep01" "gen_pep01" "gen_pep01" "gen_pep03" "gen_pep05"
# [6] NA NA NA NA NA
# [11] NA NA
Thanks a lot for your time, have a great day!