similar to: Add a vector to the values in a specific dimension of an array

Displaying 20 results from an estimated 10000 matches similar to: "Add a vector to the values in a specific dimension of an array"

2011 Feb 18
6
sort a 3 dimensional array across third dimension ?
I'm attempting to sort a 3 dimensional array that looks like this > x , , 1 [,1] [,2] [1,] 9 9 [2,] 7 9 , , 2 [,1] [,2] [1,] 6 5 [2,] 4 6 , , 3 [,1] [,2] [1,] 2 1 [2,] 3 2 Such that it ends up like this .... > y , , 1 [,1] [,2] [1,] 2 1 [2,] 3 2 , , 2 [,1] [,2] [1,] 6 5 [2,] 4 6 , , 3 [,1] [,2]
2012 Jan 08
1
Difference across the Nth dimension of an array
I have a multidimensional array - in this case with 4 dimensions of x,y,z and time. I'd like to take the time derivative of this matrix, i.e. perform the diff operator along dimension number 4. In Matlab, there is a simple option to specify which dimension the difference is to be taken across., but I can't see this in R. I realise I can use aperm to rotate my array so that time is in
2003 Oct 31
4
Array Dimension Names
I would like to reference array dimensions by name in an apply and a summary function. For example: apply(x, "workers", sum) Is there a better way to do this than creating a new attribute for the array and then creating new methods for apply and summary? I don't want to name the individual elements of each dimension (such as with dimnames) but rather name the dimensions. Thanks
2011 Mar 08
1
repeat matrix column within each array third dimension
Hello all, I'm working with a matrix that will have varying dimensions. It will populate an array such that the number of matrix columns will determine the number of 3rd dimension levels of the array. Rows will be the same for both. For this example lets say the array will have 2 columns, but that's not fixed. dim(arr)<-c(dim(mat)[1],2,dim(mat)[2]) I wish to repeat each matrix
2010 Apr 18
3
xtabs() of proportions, and naming a dimension (not a row)
Hi, xtabs() creates a table of counts. I want a table of proportions -- that is, I want to divide every vector (along a particular dimension) by its sum. The tiny example below does that. The call to xtabs() creates a matrix "A" with dimensions ("x1","x2","y"). I transform "A" using aperm() and aaply() to get the matrix "B". The
2017 Jun 01
0
Reversing one dimension of an array, in a generalized case
On the off chance that anyone is still interested, here is the corrected function using aperm(): z <- array(1:120,dim=2:5) f2 <- function(a, wh) { idx <- seq_len(length(dim(a))) dims <- setdiff(idx, wh) idx <- append(idx[-1], idx[1], wh-1) aperm(apply(a, dims, rev), idx) } all.equal(f(z, 1), f2(z, 1)) # [1] TRUE all.equal(f(z, 2), f2(z, 2)) # [1] TRUE
2012 Feb 09
2
fill an array by rows
I've dug around but not been able to find anything, am probably missing something obvious. How can I fill a three-dimensional (or higher dimension) array by rows instead of columns. eg new1 <- array(c(1:125), c(5,5,5)) works fine for me but fills it by columns and new2 <- array(c(1:125), c(5,5,5), byrow=TRUE) throws an error. Am I missing something obvious? I also tried
2017 Jun 01
1
Reversing one dimension of an array, in a generalized case
Thanks again. I am going to try the different versions. But I probably won't be able to get to it till next week. This is probably at the point where anything further should be sent to me privately. -Roy > On Jun 1, 2017, at 1:56 PM, David L Carlson <dcarlson at tamu.edu> wrote: > > On the off chance that anyone is still interested, here is the corrected function using
2005 Aug 16
3
how to reshape an array avoiding for loops
Dear r-help, I have an array a1 with dimensions [1:660,1:65,1:25] I would like the first dimension to be the last one. That is I want and array [1:65,1:25,1:660] The only way to do this, I know, is tmp.a<-array(dim=dim(a1)[c(2,3,1)]) for(i in 1:dim(a1)[1]) tmp.a[,,i]<-a1[i,,] a1<-tmp.a rm(tmp.a) Is it possible to avoid 'for' loop here? Thank you! ---
2011 Jul 27
2
Elegant way to subtract matrix from array
there are really two related problems here I have a 2D matrix A <- matrix(1:100,nrow=20,ncol =5) S <- matrix(1:10,nrow=2,ncol =5) #I want to subtract S from A. so that S would be subtracted from the first 2 rows of #A, then the next two rows and so on. #I have a the same problem with a 3D array # where I want to subtract Q for every layer (1-10) in Z # I thought I solved this one
2017 Jun 01
3
Reversing one dimension of an array, in a generalized case
> On 1 Jun 2017, at 22:42, Roy Mendelssohn - NOAA Federal <roy.mendelssohn at noaa.gov> wrote: > > Thanks to all for responses/. There was a question of exactly what was wanted. It is the generalization of the obvious example I gave, > >>>> junk1 <- junk[, rev(seq_len(10), ] > > > so that > > junk[1,1,1 ] = junk1[1,10,1] > junk[1,2,1] =
2013 Feb 14
3
list of matrices --> array
i'm somehow embarrassed to even ask this, but is there any built-in method for doing this: my_list <- list() my_list[[1]] <- matrix(1:20, ncol = 5) my_list[[2]] <- matrix(20:1, ncol = 5) now, knowing that these matrices are identical in dimension, i'd like to unfold the list to a 2x4x5 (or some other permutation of the dim sizes) array. i know i can initialize the array, then
2010 Jan 12
1
coerce vector into array - change filling sequence
Dear all, When I coerce a vector into a multi dimensional array, I would like R to start filling the array along the last dimension, then the 2nd last etc. Let's jump straight into an example. x <- 1 : 24 y <- array(dim=c(2,2,6)) I would like to have: y[1,1,1] = 1 y[1,1,2] = 2 ... y[1,1,6] = 6 y[1,2,1] = 7 y[1,2,2] = 8 ... y[2,1,1] = 13 ... y[2,2,1] = 19 if I do y<- array(x,
2005 Jul 25
2
A one-liner to create a 3-dim array
Hi, I would like to write a one-line R code to create a 3-dim array, B, of dimension (n,n,m) from a matrix, A, of dimension (m,n) such that the i-th element of the 3-dim array, B[, , i] is the outer product of the i-th row of A. Thanks for any help, Ravi. [[alternative HTML version deleted]]
2011 Nov 26
5
cumsum in 3d arrays
Hello! Is it posible to apply /cumsum()/ along the 3rd dimension of 3D array? Something like matrlab function - /cumsum (*A*,dim)/ which returns the cumulative sum of the elements along the dimension of *A* specified by scalar dim. Thanks in advance ?eljka -- View this message in context: http://r.789695.n4.nabble.com/cumsum-in-3d-arrays-tp4110470p4110470.html Sent from the R help mailing
2007 Aug 24
2
Applying a function to an array
Dear R-users, I would like to apply a function (more precisely sd()) over the third dimension of a three-dimension array. The function apply would be interesting but the chosen function can only be applied on the rows and columns of the array according to the help file. I can use a loop to cut the array in matrices and then use apply for each replication, but it's not very nice. A small
2003 Sep 25
1
apply on a 4D array
I am trying to multiply a 3D array of 4x4x4 by the 4 3D arrays of a 4D array with dimensions 4x4x4x4 (the last dimension being the one that I want to split by). (4x4x4 array) > hiaAry , , a1 i1 i2 i3 i4 h1 9.5936098 6.001040 0.08772 0.3138600 h2 1.2003500 1.454570 2.79248 0.0000000 h3 0.1346500 0.201220 0.39256 0.5464000 h4 0.0109000 0.012270 0.16417 0.2766900 ,
2009 Nov 09
1
multiple tests: t-statistic for vectors in 4-dimensional array
Hi everyone, I created a four dimensional vector (dim (128,128,1,8)). This third dimension is necessary for another function somewhere. Now I'd like to perform a t-test on every vector of length 8 in my array on the fourth dimension. I'd like to obtain a new array of three dimensions with dimensions 128x128x1 with all these test statistics. I tried this with a double loop: A <-
2012 Oct 15
2
Chopping a two column data frame by rows into a three dimensional array.
If I have a two column data frame like: > dat <- cbind("x"=c(1:100),"y"=c(100:1)) How can I create an array that splits every ten rows of that data frame into a third dimension of an array so that: > newarray[,,1] ,,1 x y 1 100 2 99 3 98 ... ... 10 91 ,,2 x y 11 90 12 89 ... ... ... Thanks. [[alternative HTML version deleted]]
2011 Jan 10
1
replace values in array with means of certain values in array
Een ingesloten tekst met niet-gespecificeerde tekenset is gescrubt ... Naam: niet beschikbaar URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110110/596768d9/attachment.pl>