Re: [Rd] Unexpected behavior of '[' in an apply instruction

2021-02-12 Thread Avi Gross via R-devel
doable. You can treat the array x as a vector just like lower level R does and access the contents using the formula it uses. -Original Message- From: R-devel On Behalf Of Sokol Serguei Sent: Friday, February 12, 2021 5:50 PM To: r-devel@r-project.org Subject: Re: [Rd] Unexpected behavior of

Re: [Rd] Unexpected behavior of '[' in an apply instruction

2021-02-12 Thread Sokol Serguei
Le 12/02/2021 à 23:49, Sokol Serguei a écrit : Le 12/02/2021 à 22:23, Rui Barradas a écrit : Hello, Yes, although there is an accepted solution, I believe you should post this solution there. It's a base R solution, what the question asks for. And thanks, I would have never reminded myself

Re: [Rd] Unexpected behavior of '[' in an apply instruction

2021-02-12 Thread Sokol Serguei
Le 12/02/2021 à 22:23, Rui Barradas a écrit : Hello, Yes, although there is an accepted solution, I believe you should post this solution there. It's a base R solution, what the question asks for. And thanks, I would have never reminded myself of slice.index. There is another approach -- pr

Re: [Rd] Unexpected behavior of '[' in an apply instruction

2021-02-12 Thread Rui Barradas
Hello, Yes, although there is an accepted solution, I believe you should post this solution there. It's a base R solution, what the question asks for. And thanks, I would have never reminded myself of slice.index. Rui Barradas Às 20:45 de 12/02/21, robin hankin escreveu: Rui > x <- array(

Re: [Rd] Unexpected behavior of '[' in an apply instruction

2021-02-12 Thread robin hankin
Rui > x <- array(runif(60), dim = c(10, 2, 3)) > array(x[slice.index(x,1) %in% 1:5],c(5,dim(x)[-1])) (I don't see this on stackoverflow; should I post this there too?) Most of the magic package is devoted to handling arrays of arbitrary dimensions and this functionality might be good to include

[Rd] Unexpected behavior of '[' in an apply instruction

2021-02-12 Thread Rui Barradas
Hello, This came up in this StackOverflow post [1]. If x is an array with n dimensions, how to subset by just one dimension? If n is known, it's simple, add the required number of commas in their proper places. But what if the user doesn't know the value of n? The example below has n = 3, and