[R] avoiding eval parse with indexing
smartpink111 at yahoo.com
Sun May 26 17:32:20 CEST 2013
the code returns Error:
#Error in 1:24[1, 1, 1:3, 1:4] : incorrect number of dimensions
May be something is missing.
----- Original Message -----
From: Bert Gunter <gunter.berton at gene.com>
To: Martin Ivanov <tramni at abv.bg>
Cc: r-help at r-project.org
Sent: Sunday, May 26, 2013 10:43 AM
Subject: Re: [R] avoiding eval parse with indexing
Well, assuming I understand, one approach would be to first get the
dim attribute of the array and then create the appropriate call using
> z <- array(1:24,dim=2:4)
> d <- dim(z)
> ix <-lapply(d[-c(1,1)],seq_len)
> do.call("[", c(list(z),1,1,ix))
 1 7 13 19
Is that what you want?
On Sun, May 26, 2013 at 6:56 AM, Martin Ivanov <tramni at abv.bg> wrote:
> I would like to get an advice on how the notorious eval(parse()) construct could possibly
> be avoided in the following example. I have an array x, which can have different number of dimensions,
> but I am only interested in extracting, say, the first element of the first dimension. Currently I achieve this
> in this way:
> eval(parse(text=paste0("x[1", paste(rep(", ", length(dim(x)) - 1), collapse=""), "]")))
> Is it possible to avoid the eval parse here? How?
> Best regards,
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
Genentech Nonclinical Biostatistics
Internal Contact Info:
R-help at r-project.org mailing list
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
More information about the R-help