? stato filtrato un testo allegato il cui set di caratteri non era indicato... Nome: non disponibile URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130402/fd10647d/attachment.pl>
On 02/04/2013 6:36 AM, Enrico Bibbona wrote:> Is there any function that extends to multidimentional arrays the > functionalities of "row" and "col" which are just defined for matrices? > Thanks, Enrico BibbonaNot as far as I know, but there are a lot of functions in packages. You could write your own something like this. I've skipped any error checking; you'll want to add that. indices <- function(a, which) { d <- dim(a) prod_before <- prod(d[seq_len(which-1)]) result <- rep(seq_len(d[which]), each=prod_before, length.out = prod(d)) dim(result) <- d result } Then indices(a, 1) gives an array of the same shape as a where entry i, j, k, ... is i, indices(a, 2) has entry i,j,k, ... equal to j, etc. Duncan Murdoch
? stato filtrato un testo allegato il cui set di caratteri non era indicato... Nome: non disponibile URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130402/f0d57563/attachment.pl>
slice.index() in base On 4/2/2013 6:36 AM, Enrico Bibbona wrote:> Is there any function that extends to multidimentional arrays the > functionalities of "row" and "col" which are just defined for matrices? > Thanks, Enrico Bibbona > > [[alternative HTML version deleted]] > > ______________________________________________ > 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.