[R] accessing the ellements in an array and factors.

Jim Lemon drjimlemon at gmail.com
Fri Jun 12 12:06:45 CEST 2015


Hi Bogdan,
I seem to be able to do it like this:

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

Jim


On Fri, Jun 12, 2015 at 2:08 PM, David Winsemius <dwinsemius at comcast.net> wrote:
> Cross-posting to SO and Rhelp is deprecated.
>
> On Jun 11, 2015, at 8:40 PM, Bogdan Tanasa wrote:
>
>> Dear all,
>>
>> please could you please with a simple question : I do have an array of 32
>> elements, where each element is indexed by a name : eg :
>>
>> 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 ? Thanks a
>> lot,
>>
>> bogdan
>>
>>       [[alternative HTML version deleted]]
>>
>
> As is posting in HTML.
>
>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
> David Winsemius
> Alameda, CA, USA
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list