The bootstrap function in S+Resample lets you bootstrap arrays
with arbitrarily many dimensions. That code could be adapted for
your purpose. Here are pieces of the code (from resampMakeFunc)
that give the general idea:
(creating an expression called "ffs"):
paste("data[", indsText,
if(dimLength > 1)
paste(c(rep(",",dimLength),"drop=F"), collapse=""),
"]")
Then, run it:
eval(parse(text = ffs))
>I'm trying to extract from an array x of arbitrary dimension in the
>following way :
>
>y <- x[,1] #if x is length(dim(x)==2)
>y <- x[,,1] #if x is length(dim(x)==3)
>y <- x[,,,1] #if x is length(dim(x)==4)
>etc..
>
>The only solution I found is to transform x as a vector, extract the
>first n elements and rearrange the result as an array of appropriate
>dimensions:
>
>v <- as.vector(x)
>lv <- length(v)
>d <- dim(x)
>ld <- length(dim(x))
>n <- lv/d[ld]
>y <- array(v[1:n],dim=d[1:(ld-1)])
>
>Is there a better way to do that?
========================================================
| Tim Hesterberg Research Scientist |
| timh@insightful.com Insightful Corp. |
| (206)802-2319 1700 Westlake Ave. N, Suite 500 |
| (206)283-8691 (fax) Seattle, WA 98109-3012, U.S.A. |
| www.insightful.com/Hesterberg |
========================================================
Download the S+Resample library from www.insightful.com/downloads/libraries
Insightful 2005 User Conference
Princeton, NJ, Oct. 26-27, 2005
Don't miss the keynote by Dr. Bill Meeker!
Special Pricing: $199 Commercial/$99 Academic
www.insightful.com/news_events/2005uc
|