Displaying 4 results from an estimated 4 matches for "obattempt".
Did you mean:
obattempts
2004 Sep 08
3
do.call("[", ...) question
..."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:
do.call("[",list(a,jj))
do.call("[",c(a,jj))
do.call("[",list(a,unlist(jj)))
Of course, the one that works is
do.call("[",list(a,jj[[1]],jj[[2]]))
but I don't know how long jj is apriori so this won't do.
--
Robin Hankin
Uncertainty Analyst
So...
2004 Mar 10
3
aperm() and as.list() args to "["
...[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 aren't right either:
b[as.vector(c(1,3,2,1)[permutation]) ]
b[as.list(c(1,3,2,1)[permutation]) ]
OBattempt:
eval(parse(text=paste("b[",paste(c(1,3,2,1)[permutation],collapse=","),"]")))
which DOES work, but is ghastly!
--
Robin Hankin
Uncertainty Analyst
Southampton Oceanography Centre
SO14 3ZH
tel +44(0)23-8059-7743
initialDOTsurname at soc.soton.ac.uk (edit in obvious...
2004 Sep 13
1
do.call("dim<-" , ... )
...1, 2, 5, 6, 9,10,
3, 4, 7, 8,11,12,
13,14,17,18,21,22,
15,16,19,20,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.soto...
2004 Mar 12
1
another do.call() problem.
...vector c(1,2,3,1). As per
yesterday, I can use do.call():
a[1,2,3,1] == do.call("[",c(list(a),c(1,2,3,1)))
Now how do I apply the above technique (or indeed any other technique!) to get
a[1,2,3,]
[1] 37 101 165 229
from a vector like c(1,2,3,0) or c(1,2,3,NULL) or c(1,2,3,NA)?
OBattempts:
do.call("[",c(list(a),c(1,2,3)))
do.call("[",c(list(a),c(1,2,3),NULL))
do.call("[",c(list(a),c(1,2,3,NULL)))
do.call("[",c(list(a),c(1,2,3,",")))
none of these give what I want.
Anyone?
--
Robin Hankin
Uncertainty Analyst
Southampton Oceanogra...