As it has been noticed in Subsetting R array: dimension lost when its length is 1 R drops every dimension when subsetting and its length is 1.
The drop
property helps avoid that.
I need a more flexible way to subset :
> arr = array(1, dim= c(1,2,3,4))
> dim(arr[,,1,])
[1] 2 4
> dim(arr[,,1,,drop=F])
[1] 1 2 1 4
I want a way to subset by dropping the 3rd dimension (actually the dimension where I put the subset 1) and keepping the 1st dimension (the dimensions where no subset is put).
It should return an array with dimension = 1 2 4
My issue is that I started coding with an array with no dimension = 1, but when coming to deal with some cases where a dimension is 1, it crashes. The function I need provides a way to deal with the array as if the dimension is not 1.