Dear S-Users,
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?
Regards,
Patrick