similar to: do.call("dim<-" , ... )

Displaying 20 results from an estimated 800 matches similar to: "do.call("dim<-" , ... )"

2004 Mar 10
3
aperm() and as.list() args to "["
Hi everyone. I'm playing with aperm(): a <- 1:24 dim(a) <- c(2,3,2,2) permutation <- c(1,2,4,3) b <- aperm(a,permutation) So if my understanding is right, a[1,3,2,1] == b[c(1,3,2,1)[permutation] ] but this isn't what I want because the RHS evaluates to a vector, and I am trying to identify a single element of b. How do I modify the RHS to give what I want? Following
2004 Sep 08
3
do.call("[", ...) question
Hi again everyone I have an arbitrarily dimensional array "a" and a list "jj" of length length(dim(a)). The elements of jj are vectors of indexes. How do I use do.call() to extract a[ jj[[1]], jj[[2]], jj[[3]], ...] ? Toy example follows: a <- matrix(1:30,5,6) jj <- list(5:1,6:1) I want the following a[ jj[[1]],jj[[2]] ] How do I do this? OBAttempts:
2004 Sep 13
1
Rd files with "%" (was: permuting dimensions)
Professor Ripley thanks for this. Very much appreciated. The original subject line reflected my late-night conviction that the answer might involve passing a strange list to do.call(). Anyway, package magic is broken (only in R-devel, I might add) because I have a function called "%eq%". R-2.0.0 CMD check is stopping (I think) because it interprets the "%" as a
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]]
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
2006 Jun 09
1
Idempotent apply
Dear all, I have been working on an idempotent version of apply, such that applying a function f(x) = x (ie. force) returns the same array (or a permutation of it depending on the order of the margins): a <- array(1:27, c(2,3,4)) all.equal(a, iapply(a, 1, force)) all.equal(a, iapply(a, 1:2, force)) all.equal(a, iapply(a, 1:3, force)) all.equal(aperm(a, c(2,1,3)), iapply(a, 2, force))
2009 Apr 01
2
Matrix multiplication - code problem
Hi listers, I am having some trouble in a matrix multiplication... I have already checked some posts, but I didn't find my problem... I have the following code... But I am not getting the right multiplication... I checked the dimension and they are fine... id_y <- array(1:10,dim=c(2,1,5)) id_yt<-aperm(id_y,c(2,1,3)) m_id<-array(dim=c(dim(id_y)[1],dim(id_y)[1],dim(id_y)[3])) for (i in
2004 Sep 15
2
efficient submatrix extraction
Hi, I have a matrix of say 1024x1024 and I want to look at it in chunks. That is I'd like to divide into a series of submatrices of order 2x2. | 1 2 3 4 5 6 7 8 ... | | 1 2 3 4 5 6 7 8 ... | | 1 2 3 4 5 6 7 8 ... | | 1 2 3 4 5 6 7 8 ... | ... So the first submatrix would be | 1 2 | | 1 2 | the second one would be | 3 4 | | 3 4 | and so on. That is I want the matrix to be evenly divided
2010 Dec 27
1
aperm() should retain class of input object
aperm() was designed for multidimensional arrays, but is also useful for table objects, particularly with the lattice, vcd and vcdExtra packages. But aperm() was designed and implemented before other related object classes were conceived, and I propose a small tune-up to make it more generally useful. The problem is that aperm() always returns an object of class 'array', which
2009 Feb 24
2
Transpose array
Hi Listers, Is there a way that I can transpose an array... Suppose I have the following array... x<-array(c(1,2,3,4),dim=c(1,2,2)) , , 1 [,1] [,2] [1,] 1 2 , , 2 [,1] [,2] [1,] 3 4 And I would like to get the following result... , , 1 [,1] [1,] 1 [,2] 2 , , 2 [,1] [,2] [1,] 3 [,2] 4 Thanks in advance, Marcio -- View this message in context:
2010 Jul 29
1
Using 'dimname names' in aperm() and apply()
I think that the "dimname names" of tables and arrays could make aperm() and apply() (and probably some other functions) easier to use. (dimname names are, for example, created by table() ) The use would be something like: -- x <-table( from=sample(3,100,rep=T), to=sample(5,100,rep=T)) trans <- x / apply(x,"from",sum) y <- aperm( trans,
2000 Jun 13
1
problem with aperm? (PR#568)
R version 1.0.1 OS RedHat Linux 6.1 In attempting to test for numeric vectors in a data frame, I tried: apply(dataframe,2,is.numeric) and found that it returned FALSE for all vectors whether they were numeric or not. I tracked this to the fact that as.array() was converting the data frame to character vectors, and thought I could solve it by using array(), which preserved the mode of the
2012 Jul 09
2
Read vector as multi-dimensional data in R by row
Dear R users Say I wanted to read a vector into R as multi-dimensional array by row, e.g. a<-c(1:20) > b<-array(a,dim=c(2,5,2)) > b , , 1 [,1] [,2] [,3] [,4] [,5] [1,] 1 3 5 7 9 [2,] 2 4 6 8 10 , , 2 [,1] [,2] [,3] [,4] [,5] [1,] 11 13 15 17 19 [2,] 12 14 16 18 20 But actually I wanted... [,1] [,2] [,3] [,4] [,5]
2017 Sep 28
2
building random matrices from vectors of random parameters
Sure -- thanks -- only took me 3-4 attempts to get aperm to work (as opposed to really thinking hard about how it works ;-) On 9/28/2017 11:55 AM, Duncan Murdoch wrote: > On 28/09/2017 9:10 AM, Evan Cooch wrote: >> Thanks for both the mapply and array approaches! However, although >> intended to generate the same result, they don't: >> >> # mapply approach
2017 Sep 28
3
building random matrices from vectors of random parameters
Thanks for both the mapply and array approaches! However, although intended to generate the same result, they don't: # mapply approach n = 3 sa <- rnorm(n,0.8,0.1) so <- rnorm(n,0.5,0.1) m <- rnorm(n,1.2,0.1) mats = mapply(function(sa1, so1, m1) matrix(c(0,sa1*m1,so1,sa1),2,2,byrow=T), sa, so, m, SIMPLIFY = FALSE) print(mats) [[1]] ????????? [,1]????? [,2] [1,] 0.0000000
2019 Jul 08
5
Format printing inside a matrix
Hi Abby, Thanks a lot for your paraphrasing and your suggestion! The problem of wrapping the list into a S3/S4 object, i.e. subclassing array or matrix, is that one also has to define a bunch of methods for subsetting, joining, etc, in order to make it behave like a list array. The reason is that most R functions for subsetting, joining, etc. do not preserve class attributes of the input, which
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
2011 May 19
2
Add a vector to the values in a specific dimension of an array
Hello, A simple question, although I can't find an answer via my google/forum search: I have a 4-dimensional array; call it A[1:M,1:N,1:P,1:Q]. I have a vector x that is N by 1. I would like to "quickly" add x to the 2nd dimension of A; in other words, I want a quicker way of doing the following: for (m in 1:M) { for (p in 1:P) { for (q in 1:Q) { A[m,,p,q] =
1999 Jul 20
2
tensor() function and sets
Hi Everyone, To complete the outer() and kronecker() functions in the base, may I suggest the following tensor() function, which allows the multiplication of arrays through sets of conformable dimensions. I am happy to write a help page if required. The code also needs a setdiff() function which prompts me to ask: what about simple set functions? I expect many of us have written our own
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