Re: [R] Inflated Array

From: Ben Bolker <bolker_at_ufl.edu>
Date: Wed 19 Jul 2006 - 02:07:39 EST

Hadassa Brunschwig <dassybr <at> gmail.com> writes:

>
> Hi R-users!
>
> I am trying to create a what I call inflated array (maybe there is
> already some other name for that). It is an array that changes
> dinamically its dimensions, e.g. the higher the number of third
> dimensions, the more rows in the array.

  base R doesn't have a data structure for this: arrays in R must not be "ragged" (i.e., every sub-array must have the same dimensions).

  So you would need to use a list of matrices in your example. I don't quite know the logic that you're using to decide what goes in each sub-table.

The basic example you give could be built by hand as follows:

list(1:4,matrix(5:12,byrow=TRUE,ncol=4),

         matrix(13:24,byrow=TRUE,ncol=4))

  if you had used scan() or something else to get a long, flat vector (x) and also had a vector (v) that indicated the number of rows in each sub-table:

x <- 1:24
nrow <- c(1,2,3)
ncol <- 4

ind <- rep(1:length(nrow),ncol*nrow)
lapply(split(x,ind),

    matrix,ncol=ncol,byrow=TRUE)

  seems to work.

  cheers
   Ben Bolker



R-help@stat.math.ethz.ch 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. Received on Wed Jul 19 02:20:03 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 19 Jul 2006 - 04:16:59 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.