I have the following matrix "m" (nrow=2504, ncol=2) with two columns; one called ind (from index) and the other called headerline (IDs of samples):
> head(m)
ind headerline
[1,] "1" "HG00096"
[2,] "2" "HG00097"
[3,] "3" "HG00099"
[4,] "4" "HG00100"
[5,] "5" "HG00101"
[6,] "6" "HG00102" ...
And the following index vector called "index" (nr=385, nc=1):
> head(index)
V1
1 1
2 4
3 9
4 12
5 13
6 16 ...
I want to subset the samples in the row positions marked by index (I want a new matrix with sample in row 1, sample in row 4, sample in row 9 and so forth). I came up with the following code:
for i in index { dudosos<-subset(headerline,ind==i, select=c(headerline)) }
but it yields the following error:
Error: unexpected symbol in "for i"
I don't know what that error is telling me, it's too vague. Help? Thanks!
Desired output:
> head(m) #or other name
ind headerline
"1" "HG00096"
"4" "HG00100"
"9" ...