I have to compare two star catalogs, the problem is that the names of stars are different in each catalog. For comparision, I have a third catalog with common names of each star. So I need to crosscheck two lists with a third and create a fourth containing all star properties. Im summary, consider the following catalogs:
hypatia={"HIP87382", "2MASS19290895+4311502", "HIP98314", "HIP98316", "HIP106931",...}
names={{"2259072226846681494447849441045193405", "HIP87382", "HD162826",
"BD+4003225B+4003225", "2MASS17511402+4004208",
"GaiaDR21344497769227698432", "TYC3093-01946-1", "HR06669",
"GaiaDR11344497764930721536"},...}
I need to create a list where each entry correspond to a list {i,j}
, i
beeing the position of name hypatia[[j]]
in names
list. I tried the following brute force method:
indhyp={}
Do[
If[MemberQ[names[[i]], hypatia[[j]]],
indhyp = Append[indhyp, {i, j}]],
{i, 1, Length[names]}, {j, 1, Length[hypatia]}
]
The problem is that this code returns the following:
{{1, 1612}, {1, 1613}, {4, 725}, {4, 726}, {4, 727}, {5, 1042},...}
As can be seen, the first two terms are repeated, meaning that both hypatia[[1612]]
and hypatia[[1613]]
appears in the position names[[1]]
. That's wrong, as hypatia[[1612]]
and hypatia[[1613]]
are different stars with different names.
I have no clue why.
Is there any other non brute force method, or any clue why this problem is happening?
poslist = Position[names, #] & /@ hypatia
. This should give you a list of singletons, each containing the desired position specification; check that that's the case withMatchQ[poslist, {{{___}}...}]
. If you getTrue
, then you can safely take the first (and only) element of each:poslist = First /@ poslist
But if you getFalse
, let me know... $\endgroup$MatchQ[names, {{___String}...}]
andMatchQ[hypatia, {___String}]
, right? $\endgroup$