Yes, for the record, the typo in my earlier post is corrected below.
(Martin's previous "correction" both corrected and slightly
changed
what I provided).
-- Bert
On Sun, May 26, 2013 at 7:43 AM, Bert Gunter <bgunter at gene.com>
wrote:> Martin:
>
> Well, assuming I understand, one approach would be to first get the
> dim attribute of the array and then create the appropriate call using
> that:
>
>> z <- array(1:24,dim=2:4)
>> d <- dim(z)
############>> ix <-lapply(d[-c(1,2)],seq_len)
^ ## I typed c(1,1) previously,
a mistake.
################
>> do.call("[", c(list(z),1,1,ix))
> [1] 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:
>> Hello,
>> 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,
>>
>> Martin
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> 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
> Website:
>
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm
--
Bert Gunter
Genentech Nonclinical Biostatistics
Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm