[R] converting a multi-dimentional array into a data frame

Allan Strand stranda at cofc.edu
Fri Jan 26 15:13:42 CET 2001

Hi all,

I've got a question that seems like it is probably easy to solve in R.
Unfortunately, I can't seem to wrap my mind around it.  

I am trying to construct a data frame with indicator variables for
various combinations of factors.  I generate a multidimensional array
using table on the factors.  This results in a contingency table that
I want to change into a dataframe where factors are equal to dimnames
from the array, and the levels of each dimension are levels of the
factors in the dataframe. 

If you are curious,
The details are this:

I have an input dataset which consists of the following
population-genetic data:

population locus individual chromosome allele
1          1     1          0          103
1          1     1          1          105
          .     .          .           .
.          .     .          .           .

So the top two rows code for a genotype at locus 1 for an individual
from population 1.  This individual is heterozygous with alleles 103
and 105.  I use table to convert this data into a locus x pop x ind x
chromosome x allele array.  The cells then take values of 0/1
depending if a particular combination exists.  This is the information
I would like to "flatten out".  It then is possible to use an anova
framework to analyze these 0/1 indicators to make population-genetic
inferences (1).  I included these details, because I am happy to
entertain suggestions for a simpler, less memory hogging approach to
the larger problem rather than the more specific question I asked


(1) Weir. 1996. Genetic Data Analysis.  Sinauer.

Allan Strand,   Biology    http://linum.cofc.edu
College of Charleston      Ph. (843) 953-8085
Charleston, SC 29424       Fax (843) 953-5453

r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list