[R] Qs re writing/reading arrays, dataframes

2010-12-13 Thread Roy Shimizu
Hi!  I'm just getting started with R (and with the analysis of large
datasets in general).  I have several beginner-level questions whose
answers I have not been able to find, and was hoping one of you would
be kind enough to throw me a cluebrick or two.

I have a 6-dimensional numeric array (which I'll call myarray) that is
fully named.  By this I mean that non-NULL dimnames are assigned to
all dimensions, and, furthermore, the dimensions themselves are named.
 In fact, I created the dimnames attribute with an expression of the
form:

dimnames(myarray) - list(line=c(...), compound:name=c(...),
compound:concentration=c(...), time=c(...), replicate=c(...),
antibody:name=c(...))

...where the values passed for attributes line, compound:name, ..,
antibody:name are all vectors with mode character.

Question 1: I'd like to save this array in a file having an ASCII
(i.e. non-binary) format that can be easily read by R.  How can I
format this file so that not only the dimnames are specified, but also
the names of the dimensions (line, compound:name, ...,
antibody:name) themselves?  I thought that the output of write.table
would give me a clue, but in fact this output does not mention the
dimension names at all.

Question 2: In fact, I don't think that write.table is the right
function to use in this case, because it seems to be designed for
dataframes rather than arrays.  When write.table coerces myarray into
a data.frame, dimensions 2-6 get collapsed into one.  Hence, when the
data is read back into R, it has the wrong dimensions.  What's the
best way to convert a fully named array like myarray into a
data.frame, so as to preserve all the array's dimnames and dimension
names?

Question 3: I've come across several times the advice to the effect
that data.frames are usually the best choice of representation for
such data.  In my case, however, I don't see what I would be gaining
by casting my array into a data.frame.  In what kind of situation is
it advantageous to work with a data.frame rather than an array?

Thanks in advance!

Roy

__
R-help@r-project.org mailing list
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.


Re: [R] Qs re writing/reading arrays, dataframes

2010-12-13 Thread David Winsemius


On Dec 13, 2010, at 12:20 PM, Roy Shimizu wrote:


Hi!  I'm just getting started with R (and with the analysis of large
datasets in general).  I have several beginner-level questions whose
answers I have not been able to find, and was hoping one of you would
be kind enough to throw me a cluebrick or two.

I have a 6-dimensional numeric array (which I'll call myarray) that is
fully named.  By this I mean that non-NULL dimnames are assigned to
all dimensions, and, furthermore, the dimensions themselves are named.
In fact, I created the dimnames attribute with an expression of the
form:

dimnames(myarray) - list(line=c(...), compound:name=c(...),
compound:concentration=c(...), time=c(...), replicate=c(...),
antibody:name=c(...))

...where the values passed for attributes line, compound:name, ..,
antibody:name are all vectors with mode character.

Question 1: I'd like to save this array in a file having an ASCII
(i.e. non-binary) format that can be easily read by R.


?dump



How can I
format this file so that not only the dimnames are specified, but also
the names of the dimensions (line, compound:name, ...,
antibody:name) themselves?  I thought that the output of write.table
would give me a clue, but in fact this output does not mention the
dimension names at all.

Question 2: In fact, I don't think that write.table is the right
function to use in this case, because it seems to be designed for
dataframes rather than arrays.  When write.table coerces myarray into
a data.frame, dimensions 2-6 get collapsed into one.  Hence, when the
data is read back into R, it has the wrong dimensions.  What's the
best way to convert a fully named array like myarray into a
data.frame, so as to preserve all the array's dimnames and dimension
names?

Question 3: I've come across several times the advice to the effect
that data.frames are usually the best choice of representation for
such data.  In my case, however, I don't see what I would be gaining
by casting my array into a data.frame.  In what kind of situation is
it advantageous to work with a data.frame rather than an array?


When you are going to do regression.



Thanks in advance!



David Winsemius, MD
West Hartford, CT

__
R-help@r-project.org mailing list
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.