[R] How to write and analyze data with 3 dimensions

Greg Snow 538280 at gmail.com
Fri Mar 23 20:32:03 CET 2012

You could put this data into a 3 dimensional array and then use the
apply function to apply a function (such as mean) over which ever
variables you choose.

Or you could put the data into a data frame in long format where you
have your 3 variable indices in 3 columns, then the data in a 4th
column.  Then use the tapply function to apply the mean (or other
function) to groups based on the indices of choice.

If you want to do fancier things in either case then look into the
reshape2 and plyr packages for ways of shaping the data and taking the
data apart into pieces, apply a function to each piece, then put it
all back together again.

On Tue, Mar 20, 2012 at 11:16 AM, jorge Rogrigues <hjmygt at gmail.com> wrote:
> Suppose I have data organized in the following way:
> (P_i, M_j, S_k)
> where i, j and k and indexes for sets.
> I would like to analyze the data to get for example the following
> information:
> what is the average over k for
> (P_i, M_j)
> or what is the average over j and k for P_i.
> My question is what would be the way of doing this in R.
> Specifically how should I write the data in a csv file
> and how do I read the data from the csv file into R and perform these basic
> operations.
> Thank you.
>        [[alternative HTML version deleted]]
> ______________________________________________
> R-help at 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.

Gregory (Greg) L. Snow Ph.D.
538280 at gmail.com

More information about the R-help mailing list