I have data in a matrix in the following way:
label 1 2 3 4
id_101 10 30 43 32
id_102 3 32 43 43
id_111 45 34 22 66
id_201 87 65 66 34
id_202 45 76 76 44
......
this data has been transformed in a list so it is like:
[[1]]
[1] label 1 2
[3] 3 4
[[2]]
[1] id_101 .....
......
what I want is to know if a value a matches one of the values from the column named label. For that purpose I am using a for loop with the match instruction:
a<-"id_201" ///for example
for (pos in 2:length(matrix))
{
if (!is.na(match(a,tabd[[pos]][[1]])))
{
found<-1
print(found)
break
}
}
if (found) print(pos)
I was wondering if there is an efficient way to look if the value from the variable a matches any value of the column under label and to get its position, but without using the for loop.
Thanks
I have made a list somewhat like what you describe, although it prints with surounding double quotes. Working with it suggests this should work