From r.hankin at noc.soton.ac.uk  Tue Nov 29 16:36:51 2005
From: r.hankin at noc.soton.ac.uk (Robin Hankin)
Date: Tue, 29 Nov 2005 15:36:51 +0000
Subject: [Rd] x[1,], x[1,,], x[1,,,], ...
In-Reply-To: <971536df0511290717k17440617qc98d4413325728ed@mail.gmail.com>
References: <4384498B.1080401@maths.lth.se>
	<EFF39129-E649-4485-BB79-00EAE5805B46@soc.soton.ac.uk>
	<971536df0511290717k17440617qc98d4413325728ed@mail.gmail.com>
Message-ID: <4AC6BD2E-651A-41F6-873B-092E54B164D9@soc.soton.ac.uk>

Hi everyone

apltake() is part of magic_1.3-20, which I only uploaded to CRAN
this morning.  Perhaps I should have mentioned this!

[
this version of the magic package also includes a whole slew
of functions that operate on arbitrary dimensioned arrays including
adiag(), apad(), arow(), arot(), arev()


enjoy!
]



On 29 Nov 2005, at 15:17, Gabor Grothendieck wrote:

> I couldn't find it:
>
>> library(magic)
>> apltake
> Error: object "apltake" not found
>
> On 11/29/05, Robin Hankin <r.hankin at noc.soton.ac.uk> wrote:
>> Hi everyone
>>
>>
>> apltake(x,1)
>>
>> [where apltake() is part of library(magic)]
>>
>> does this.
>>
>> best wishes
>>
>> Robin
>>
>>
>>
>>
>> On 23 Nov 2005, at 10:50, Henrik Bengtsson wrote:
>>
>>> Hi,
>>>
>>> is there a function in R already doing what I try to do below:
>>>
>>> # Let 'x' be an array with *any* number of dimensions (>=1).
>>> x <- array(1:24, dim=c(2,2,3,2))
>>> ...
>>> x <- array(1:24, dim=c(4,3,2))
>>>
>>> i <- 2:3
>>>
>>> ndim <- length(dim(x))
>>> if (ndim == 1)
>>>    y <- x[i]
>>> else if (ndim == 2)
>>>    y <- x[i,]
>>> else if (ndim == 3)
>>>    y <- x[i,,]
>>> else ...
>>>
>>> and so on.  My current solution is
>>>
>>> ndim <- length(dim(x))
>>> args <- rep(",", ndim)
>>> args[1] <- "i"
>>> args <- paste(args, collapse="")
>>> code <- paste("x[", args, "]", sep="")
>>> expr <- parse(text=code)
>>> y <- eval(expr)
>>>
>>> ndim <- length(dim(x))
>>> args <- rep(",", ndim)
>>> args[1] <- "i"
>>> args <- paste(args, collapse="")
>>> code <- paste("x[", args, "]", sep="")
>>> expr <- parse(text=code)
>>> y <- eval(expr)
>>>
>>> Is there another way I can do this in R that I have overlooked?
>>>
>>> /Henrik
>>>
>>> ______________________________________________
>>> R-devel at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
>> --
>> Robin Hankin
>> Uncertainty Analyst
>> National Oceanography Centre, Southampton
>> European Way, Southampton SO14 3ZH, UK
>>  tel  023-8059-7743
>>
>> ______________________________________________
>> R-devel at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743



[Rd] x[1,], x[1,,], x[1,,,], ...
Robin Hankin