Displaying 20 results from an estimated 9000 matches similar to: "Inflate/Expand/Resize an array"
2007 Jun 07
2
Display Multiple page lattice plots
Gudday,
I am generating a series of lattice contourplots that are conditioned on a variable (Year) that has 27 different levels. If I try and put them all on one plot, it ends up pretty messy and you can't really read anything, so instead I have set the layout to 3x3, thus generating three pages of nine plots each. The problem is that I can't display all these on screen at once, because
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
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
2007 May 03
3
Filling array: No recycling
Hello,
is it possible to fill an array with no using of the recycling rule?
My problem. I want to fill an array but my values have not always
the same length.
My aim. I want to fill the array only ONE TIME. All vacent places
should be written with NA.
Thank's a lot.
Felix
Example:
--------
#Write 1 to 3 only one time. The last
#5 place should be NA.
dim(as.array(letters))
array(1:3,
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,
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
2006 Nov 17
2
do.call("+", ...)
Hi
How do I make do.call() take "+" as a function for a list of more
than two elements?
Toy problem follows:
f <- function(i){matrix((1:6)^i,2,3)}
# Thus f() returns a matrix of size 2x3; I want to add a whole bunch
of such matrices,
# as in f(1) + f(2) + f(3) + f(4)
# But:
> do.call("+",sapply(1:4,f,simplify=FALSE))
Error in do.call("+",
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
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 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"
)
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
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
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
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 Mar 15
3
empty array
Hi the list
Is it possible to create an empty matrix ? I do not mean an matrix with
a single value that is NA (which is not empty) but a real empty one,
with length=0.
I do not understand why we have length(numeric()), length(factor()) and
length(character()) to zero, and length(array()) to one... Any rason for
that ?
Thanks
Christophe
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))
2006 Oct 19
2
arraytake for extracting subarrays from multidimensional arrays
Hi,
I recently encountered a problem with array subsetting and came up with a
fix. Given an array of arbitrary dimensions, in which the number of
dimensions is only known at runtime, I wanted to extract a subarray. The
main issue with doing this is that in order to extract a subarray from an
array of (say) 4 dimensions you usually specify something like this
a.subarray <- a[,c(4,2),1:5,]
2005 Nov 17
3
changing figure size in Sweave
Hi
In Sweave, how does one change the size of the plots?
I tried using a hook:
<<echo=FALSE, print=FALSE, fig=TRUE>>=
options(SweaveHooks=list(fig=function() ps.options(width=1)))
library(graphics)
pairs(iris)
@
but this didn't change the size of the figure. How to make the
figures a
different size?
--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre,
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
2006 Sep 13
3
functions and strings
Hi
If
string <- "xyz"
f <- function(x){1 + sin(cos(x)) + exp(x^2)}
How do I manipulate "string" and f() to give the string
"1 + sin(cos(xyz)) + exp(xyz^2)"
?
--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
tel 023-8059-7743