Displaying 20 results from an estimated 135 matches for "aperm".
Did you mean:
aper
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...
2000 Jun 13
1
problem with aperm? (PR#568)
...d 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 columns.
However, I then got an error from aperm():
Error in aperm(X, c(s.call, s.ans)) : aperm: invalid second argument,
must be a vector
even though the second argument tested as a vector. This happened both
within the apply() function and calling aperm() separately, even if I
explicitly used a numeric vector for the second argument. I then...
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, c("fr...
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...
2010 Jul 26
2
the real dimnames
...d now, printing a prints these dimension labels nicely:
> A
to
from [,1] [,2] [,3]
[1,] 1 4 7
[2,] 2 5 8
[3,] 3 6 9
I don't know exactly what these labels are called, but they can be
handy sometimes.
For example, they could be handy when using aperm. Instead of writing
aperm(A, c(2,1) )
It would be nice to be able to write:
aperm(A, c("from","to") )
This way, I don't have to remember what is the order of the dims of A.
It is easy to extend the functionality of aperm, so that the above
code works:
---
my.aperm=fun...
2001 Jul 10
0
speeding up aperm/ adding repmat
Hi,
I have noticed that aperm is very slow, and I wondered if there was a
way of speeding it up.
Let me tell you a bit about the context of my problem, because perhaps
I shouldn't be using aperm at all.
The context is probabilistic inference in
graphical models. One of the most fundamental operations is two
compute an elem...
2010 Dec 15
0
Problems with the borders (High difficulty)
...80% of the seeds produced by a plant will fell into the parent cell, the 15% in the first ring according to the king movement (in chess), and a 5% in the second ring defined by the queen2 matrix. Someone said me the functions that order the position of the seed dispersed, they are:
neighb <- aperm(apply(aperm(outer(king,IJ,'+'),c(2,4,1,3)),3:4,diag),c(2,1,3)) #Seed going back into source cell???
for(i in 1:nrow(IJ)) SB[matrix(neighb[,,i],nc=2)]<- SR1[matrix(IJ[i,],1,2)]/8 + SB[neighb[,,i]] #Seed going to anuli 1 neighbor cells from all possible sources
neighb <- aperm(apply...
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:...
2006 Jun 09
1
Idempotent apply
...ion 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))
all.equal(aperm(a, c(3,1,2)), iapply(a, 3, force))
I have also generalised apply so that the function can return an array
of any dimension and it will be slotted in orthogonally to the
existing dimensions:
iapply(a, 1, min)
iapply(a, 2, min)
iapply(a, 3, min)
ia...
2017 Sep 28
0
building random matrices from vectors of random parameters
The use of aperm is unnecessary if you call array() properly.
ms <- array(c(rep(0, 5),so,sa*m,sa), c(5, 2, 2))
--
Sent from my phone. Please excuse my brevity.
On September 28, 2017 9:10:26 AM PDT, Evan Cooch <evan.cooch at gmail.com> wrote:
>Sure -- thanks -- only took me 3-4 attempts to get aperm...
2017 Sep 28
3
building random matrices from vectors of random parameters
...ng sd=0 for the parameters -- thus, every matrix will be the
same. The correct matrix would be:
???? [,1] [,2]
[1,]? 0.0 0.96
[2,]? 0.5 0.80
In fact, this is what is returned by the mapply approach, while the
array approach returns the transpose. I gather the 'missing step' is to
use aperm, but haven't figured out how to get that to work...yet.
On 9/28/2017 5:11 AM, Duncan Murdoch wrote:
> ms <- array(c(rep(0, 5),sa*m,so,sa), c(5, 2, 2))
[[alternative HTML version deleted]]
1999 Jul 20
2
tensor() function and sets
...ter)
if (no.na && no.nb)
nms <- NULL
else {
if (no.na)
na <- vector("list", length(dima))
else if (no.nb)
nb <- vector("list", length(dimb))
nms <- c(na[kpa], nb[kpb])
}
A <- matrix(aperm(A, c(kpa, da)), ncol = prod(dima[da]))
B <- matrix(aperm(B, c(db, kpb)), nrow = prod(dimb[db]))
array(A %*% B, c(dima[kpa], dimb[kpb]), dimnames = nms)
}
# examples
A <- array(1:6, 2:3, list(LETTERS[1:2], LETTERS[3:5]))
B <- 1:3
tensor(A, B, 2, 1) # same as drop(A %*% B)
A <...
2002 Jan 30
1
mosaicplot(formula, data)--- bugged?
...ure out the formula interface, and think
there's a bug, but not sure how to find it, yet alone fix it.
It seems to only work with independence models:
> data(HairEyeColor)
> mosaicplot(~ Hair + Eye + Sex, data=HairEyeColor)
> mosaicplot(~ Hair * Eye + Sex, data=HairEyeColor)
Error in aperm(a, perm, resize) : `perm' is of wrong length
here's a traceback:
> debug(mosaicplot)
> mosaicplot(~Hair + Eye + Sex + Hair:Eye, data=HairEyeColor)
debugging in: mosaicplot(~Hair + Eye + Sex + Hair:Eye, data =
HairEyeColor)
debug: UseMethod("mosaicplot")
Browse[1]>
Erro...
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
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
2004 Sep 13
1
do.call("dim<-" , ... )
...23,24,
25,26,29,30,33,34,
27,28,31,32,35,36
)),6,6)
So
identical(x[,,1] , y[1:2,1:2])
identical(x[,,2] , y[3:4,1:2])
[snip]
identical(x[,,9] , y[5:6,5:6])
all return TRUE.
OBattempts:
(i)
dim(x) <- c(4,9);x <- t(x) ; dim(x) <- c(6,6) ; y <- x
(ii)
y <- aperm(x,c(2,1,3)) ; dim(y) <- c(6,6)
Any genius out there with some ideas?
--
Robin Hankin
Uncertainty Analyst
Southampton Oceanography Centre
SO14 3ZH
tel +44(0)23-8059-7743
initialDOTsurname at soc.soton.ac.uk (edit in obvious way; spam precaution)
2010 Apr 18
3
xtabs() of proportions, and naming a dimension (not a row)
...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 problem: "B" has dimensions (<No name>, "x2",
"x1"). How can I give (back) the name "y" to the dimension with no name in
the matrix "B"? (Unless I misunderstand something, dimnames() won...
2001 Jul 18
1
hypothesis testing in models
...tion multipliers (i x k) ARRAY!!
# target: restriction value vector/scalar (k)
htest.lm <- function(object, resmat, target = 0, level = 0.95)
{
tsu <- summary(object, corr=FALSE)
cfs <- as.array(object$coefficients)
dfr1 <- nrow(resmat)
dfr2 <- object$df.residual
S <- aperm(resmat %*% aperm(cfs) - target) %*% solve(resmat %*% tsu$cov.unscaled %*% aperm(resmat)) %*% (resmat %*% aperm(cfs) - target) / (nrow(resmat) * tsu$sigma^2)
cat(" F(",dfr1,",",dfr2,") =",qf(level,dfr1,dfr2), " vs. S =",S," [ p = ",df(S,dfr1,df...
2004 Sep 13
1
Rd files with "%" (was: permuting dimensions)
...particular, how do I get
\usage{m1 %eq% m2} and \examples{..} to work nicely?
best wishes
rksh
>
>
>
>>What has this to do with the original subject line? Replacement functions
>>are not intended to be used directly, and certainly not in do.call.
>>
>>See ?aperm, as in
>>
>>xx <- x
>>dim(xx) <- c(2,2,3,3)
>>xx <- aperm(xx, c(1,3,2,4))
>>dim(xx) <- c(6, 6)
>>xx
>>
>>as required.
>>
>>BTW, you have a broken package `magic' on CRAN: please do us the courtesy
>>of fixing it so we...
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