0

I have two arrays in Julia, The array 1 (45807x2) has two columns, first column is for position of snp and second colunm is for snpID, now I want to the snpIDs that has position in array2(4580x1) from array 1. for example, the first element (5) in array 1 is the fifth snpID (BTA-34880) in array 1. how can I do it ? thanks.

45807×2 Array{Any,2}:
 1  "BovineHD0100000015"
 2  "Hapmap43437-BTA-101873"
 3  "BovineHD0100000062"
 4  "ARS-BFGL-NGS-16466"
 5  "BTA-34880"
 6  "BovineHD0100000096"
 7  "Hapmap34944-BES1_Contig627_1906"
 8  "ARS-BFGL-NGS-98142"
 9  "rs29015850"
10  "ARS-BFGL-NGS-114208"
11  "ARS-BFGL-NGS-66449"
12  "BovineHD0100000204"
13  "BovineHD0100000220"
 ⋮  


4580-element Array{Int64,1}:
 5
 6
18
25
26
54
55
67
69
84
88

1 Answer 1

2

You can directly use the second array as an index for the first array. Look at this example:

julia> using Random

julia> a = hcat(1:10, shuffle(1:10))
10×2 Array{Int64,2}:
  1   7
  2   6
  3  10
  4   1
  5   9
  6   8
  7   4
  8   5
  9   3
 10   2

julia> b = shuffle(1:5)
5-element Array{Int64,1}:
 2
 5
 3
 4
 1

julia> a[b,2]
5-element Array{Int64,1}:
  6
  9
 10
  1
  7

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.