Accessing the elements of an array and factors

158 views Asked by At

I have an array of 32 elements, where each element is indexed by a name. For instance:

list_triplet_wells <-c("A1:A2:A3", "A4:A5:A6 ",  "A7:A8:A9",   "A10:A11:A12 ")
xxx <-array(0, dim=4)
dimnames(xxx) = list(list_triplet_wells)

From another script, I have an output like :

yyy
# [1]   A1:A2:A3    B4:B5:B6
# 31 Levels:   B4:B5:B6    A1:A2:A3  ...   F4:F5:F6

so yyy seems to be a factor type. I would need to call the elements of xxx array based on the elements of yyy; eg xxx[yyy].

How can I do this in order to circumvent the factor type of yyy?

1

There are 1 answers

0
josliber On

You can convert yyy with as.character to do this sort of indexing:

xxx[as.character(yyy)]
# A1:A2:A3     <NA> 
#        0       NA