[R] avoiding eval parse with indexing
flodel at gmail.com
Sun May 26 17:07:26 CEST 2013
asub(x, 1, 1)
On Sun, May 26, 2013 at 10:43 AM, Bert Gunter <gunter.berton at gene.com> wrote:
> 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?
> -- Bert
> 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.
> Bert Gunter
> Genentech Nonclinical Biostatistics
> Internal Contact Info:
> Phone: 467-7374
> 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