Displaying 20 results from an estimated 10000 matches similar to: "Filling array: No recycling"
2006 Nov 15
2
filling an array, vectorized
Hi,
I am sure this has come up before, but my searches of the archive
didn't give any results (maybe I didn't use the right keywords, but if
I use too many, the search times out).
I have a vector of dimensions n, length is not fixed, eg
n <- c(4,5,7)
or
n <- c(19,4,5,7)
and a function f that takes a vector of indices, same length of n, and
gives a scalar.
I would like to fill
2005 Jun 13
3
extracting components of a list
Hi
how do I extract those components of a list that satisfy a certain
requirement? If
jj <- list(list(a=1,b=4:7),list(a=5,b=3:6),list(a=10,b=4:5))
I want just the components of jj that have b[1] ==4 which in this case
would be the first and
third of jj, viz list (jj[[1]],jj[[3]]).
How to do this efficiently?
My only idea was to loop through jj, and set unwanted components to
NULL,
2007 Dec 19
3
array addition
Hi
suppose I have two arrays x1,x2 of dimensions a1,b1,c1 and
a2,b2,c2 respectively.
I want x = x1 "+" x2 with dimensions c(max(a1,a2), max(b1,b2),max
(c1,c2))
with
x[a,b,c] = x1[a1,b1,c1] + x2[a2,b2,c2] if a <=min(a1,a2) , b<=min
(b1,b2), c<=min(c1,c2)
and the other bits either x1 or x2 or zero according to whether the
coordinates
are "in range" for
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:
2007 Apr 17
1
no visible binding for global variable
Hello everyone
I am trying to get one of my packages through R's QC.
The package is clean for me under R-2.4.1, R-2.5.0, and
R-devel, but Kurt gets
>
> * checking R code for possible problems ... WARNING
> hypercube: no visible binding for global variable ?f?
Function hypercube() [cut-&-pasted below] is intended to
return an adjacency matrix for an n-dimensional
2007 Jun 27
1
inherits() and virtual classes
Hi
How do I test for an object having a particular virtual class?
In the following, "onion" is a virtual class, and "octonion" is
a non-virtual class contained in onion. The last call
to inherits() gives FALSE [R-2.5.0], when inherits.Rd led
me to expect TRUE.
setClass("onion",
representation = "VIRTUAL"
)
2007 Apr 27
1
Inflate/Expand/Resize an array
Gudday,
I've had a good look everywhere trying to figure out how to do this, but
I'm afraid I can seem to find an answer anywhere - maybe its because I'm
not using the right terms, or maybe its because I'm a dummy. But
unfortunately, I am not completely and utterly stuck. Here's the
problem:
I have two large, six dimensional arrays that I would like to add
together. Lets call
2006 Oct 31
1
setReplaceMethod
Hi
If x <- 1:10 then x[5] <- 1i will promote
x to be a complex vector.
Suppose I have an S4 class "brob", and have functions
is.brob(), as.brob(), as.numeric() and so forth (minimal self-contained
code below).
If x is numeric (1:10, say) and y is a brob, what
is the best way to make
x[5] <- y
promote x to a brob in the same way as the complex example?
Or is
2004 Jan 14
1
arrows on contour lines
Hello everybody
I'm using contour() to draw streamlines of potential flow, eg
jj <- seq(from= -4, to=4,len=20)
jj <- outer(jj,jj,function(x,y){x})+1i*outer(jj,jj,function(x,y){y})
f <- function(x){x^2}
contour(Im(f(jj)), nlevels=44 , labels="")
How best to put arrows on the contour lines to show the direction of flow?
(ie I want contour lines looking like
2008 Apr 02
1
"[<-" plus drop-type extra argument
Hello
I am writing a replacement method for an S4 class and want to pass
an additional argument to "[<-"() along the lines of "["()'s "drop"
argument.
Specifically, I have an S4 class, call it "foo", with a slot 'x'
that is a
vector and a slot 'NC' that is a scalar.
I want to be able to pass a Boolean argument to the
2005 Feb 07
4
proportional matrix rows
Hi
I have a two-column integer matrix like this:
R> jj
[,1] [,2]
[1,] -1 1
[2,] -2 2
[3,] -7 6
[4,] -8 7
[5,] -6 5
[6,] -9 8
[7,] -5 4
[8,] 3 -3
[9,] -10 9
[10,] -4 3
I want a diagnostic that detects whether a row is a multiple of
the first row or not. In this case, this would be rows 1,2, and 8.
How to do this
2005 Jun 20
6
sweep() and recycling
Hi
I had a hard-to-find bug in some of my code the other day, which I
eventually
traced to my misusing of sweep().
I would expect sweep() to give
me a warning if the elements don't recycle nicely, but
X <- matrix(1:36,6,6)
sweep(X,1,1:5,"+")
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 2 9 16 23 30 32
[2,] 4 11 18 25 27 34
[3,] 6 13 20 22
2005 Apr 26
1
Index matrix to pick elements from 3-dimensional matrix
Hi all
Suppose I have a dim=c(2,2,3) matrix A, say:
A[,,1]=
a b
c d
A[,,2]=
e f
g h
A[,,3]=
i j
k l
Suppose that I want to create a 2x2 matrix X, which picks elements from
the above-mentioned submatrices according to an index matrix J referring
to the "depth" dimension:
J=
1 3
2 3
In other words, I want X to be
X=
a j
g l
since the matrix J says that the (1,1)-element should be
2006 Feb 28
2
lines() and recycled colours
Hi
?lines says
For 'type = "h"', 'col' can be a vector and will be recycled as
needed.
Why doesn't lines() recycle colours for other types?
If I type
> plot(0:1,0:1,type="n")
> lines(runif(11),runif(11),col=c("red","green"))
>
then all ten lines are red, with no warning given. Is there a reason
why
2004 Jul 13
3
(no subject)
Dear R users,
First of all, thanks for the incredibly fast answers and help of Rolf,
Marc and Robert.
Yes, I noticed that it was a lot of permutacions, but my intention was to
make this process automatic and take only 5.000 - 10.000 permutations.
Therefore, I wanted only to take that "interesting permutations" with "some
information" [inter-block permutations].
The
2005 Dec 05
1
apply() and dropped dimensions
Hi
I am having difficulty with apply(). I want apply() to return a
matrix, but sometimes a vector is returned.
Toy example follows.
Function jj() takes a couple of matrices m1 and m2 as arguments
and returns a matrix with r rows and c columns where r=nrow(m2)
and c=nrow(m1).
jj <- function(m1,m2,f,...){
apply(m1, 1, function(y) {
apply(m2, 1, function(x) {
f(x, y, ...)
2006 Mar 17
3
Element.getDimensions
Hi all,
should it be considered a bug that Element.getDimensions returns the
offsetWidth and offsetHeight properties from elemens having not
display none, but clientWidth and clientHeight from elements with
display none?
Or is it a feature?
Regards Lorenz
2006 Jul 10
1
par(mfrow,mai) and multiple plot problem
Hi
I'm having difficulty with a multiple plot. What I want is 12
plots, all of which are the same size and shape, differing
only in colour. Each one is a square, so there is an asp=1
in the plot call. I'm working in an Sweave environment so I
am free to choose the height and width of the plot.
I want the columns to be labelled at the head (here t=1,2,3)
and the rows to be labelled at
2005 Oct 05
2
eliminate t() and %*% using crossprod() and solve(A,b)
Hi
I have a square matrix Ainv of size N-by-N where N ~ 1000
I have a rectangular matrix H of size N by n where n ~ 4.
I have a vector d of length N.
I need X = solve(t(H) %*% Ainv %*% H) %*% t(H) %*% Ainv %*% d
and
H %*% X.
It is possible to rewrite X in the recommended crossprod way:
X <- solve(quad.form(Ainv, H), crossprod(crossprod(Ainv, H), d))
where quad.form() is a little
2004 Jul 13
12
Permutations
Dear R users,
I?m a beginner user of R and I?ve a problem with permutations that I don?t
know how to solve. I?ve 12 elements in blocks of 3 elements and I want only
to make permutations inter-blocks (no intra-blocks) (sorry if the
terminology is not accurate), something similar to:
1 2 3 | 4 5 6 | 7 8 9 | 10 11 12 ----------1st permutation
1 3 2 | 4 5 6 | 7 8 9 | 10 11 12 NO
- -
3 2 1