similar to: do.call("[", ...) question

Displaying 20 results from an estimated 6000 matches similar to: "do.call("[", ...) question"

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
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,
2004 Jun 11
4
rownames of single row matrices
Hi I want to extract rows of a matrix, and preserve rownames even if only one row is selected. Toy example: R> a <- matrix(1:9,3,3) R> rownames(a) <- letters[1:3] R> colnames(a) <- LETTERS[1:3] R> a A B C a 1 4 7 b 2 5 8 c 3 6 9 Extract the first two rows: R> wanted <- 1:2 R> a[wanted,] A B C a 1 4 7 b 2 5 8 rownames come through fine. Now extract just
2004 Nov 15
2
argument rationalization
Hi I am writing a bunch of functions that take two, three or four arguments. These functions operate on vectors of the same length; but I want the function to behave sensibly if one or more arguments are scalars. "+" does this for two arguments: "+"(1:10,3) # interpreted as "+"(1:10,rep(3,10)) But my functions can take more arguments. Say f() takes three:
2004 Sep 13
1
do.call("dim<-" , ... )
OK guys another problem. I have a 3D array "x" with dim(x)=c(a,a,b^2) and I want to rearrange the elements of x to make a matrix "y" with dimensions c(a*b,a*b). Neither a nor b is known in advance. I want the "n-th" a*a submatrix of y to be x[,,n] (where 1 <= n <= b^2). Needless to say, this has gotta be vectorized! Toy example with a=2, b=3 follows:
2004 Nov 17
3
3d scatter plot with drop line
This is a follow up to my question from yesterday. I want to do in R what is called a "3d scatter plot with drop lines" in S-PLUS. Basically, it's a 3dscatterplot with lines connecting the x-y grid to the z points. The lines give a better perspective on the shape of the data surface. How to? Joel Bremson UC Davis Statistics
2004 Mar 12
1
another do.call() problem.
Hi everyone suppose I have a <- array(1:256,rep(4,4)) and want to access a[1,2,3,1] by the 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)?
2004 Oct 18
2
concatenating lists elementwise
Hi How do I concatenate two lists element-by-element? Example: list.1 <- list(temperature=c("hot","cold") , size=c("big","medium")) list.2 <- list(temperature=c("lukewarm") , size=c("massive","tiny")) list.wanted <- list(temperature=c("hot","cold","lukewarm") ,
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
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, ...)
2004 Nov 11
1
axis lines crossing at origin
Hi how do I make my axes cross at the origin? x <- seq(from=-pi,to=pi,len=30) plot(x,sin(x)) makes the axes cross at about (-pi,-1). How do I get my x and y axes to cross in the centre of the graph, with the sine curve passing through the intersection? I couldn't find anything in ?par or ?axis; searching R-FAQ for "axis" didn't help. -- Robin Hankin Uncertainty
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
2004 Oct 26
1
persp(), scatterplot3d(), "..." argument
Hello list. I very often need 3d scatterplots, and use scatterplot3D quite a lot. I am trying to modify persp() to plot scatterplots, and make use of the theta and phi arguments that persp() offers. I am having some difficulty passing the correct arguments to persp(). Here is my function so far. Much of it is copied from the persp() manpage. points3d <- function(x,y,z,
2004 Oct 26
1
persp(), scatterplot3d(), "..." argument
Hello list. I very often need 3d scatterplots, and use scatterplot3D quite a lot. I am trying to modify persp() to plot scatterplots, and make use of the theta and phi arguments that persp() offers. I am having some difficulty passing the correct arguments to persp(). Here is my function so far. Much of it is copied from the persp() manpage. points3d <- function(x,y,z,
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
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
2004 May 27
2
block diagonal matrix function
Hello List I have just written a little function that takes two matrices as arguments and returns a large matrix that is composed of the two input matrices in upper-left position and lower-right position with a padding value everywhere else. (function definition and toy example below). I need nonsquare matrices and rowname() and colname() inherited appropriately. Two questions: (1) Is there a
2004 Oct 01
2
multiple dimensional diag()
Hi I have two arbitrarily dimensioned arrays, "a" and "b", with length(dim(a))==length(dim(b)). I want to form a sort of "corner-to-corner" version of abind(), or a multidimensional version of blockdiag(). In the case of matrices, the function is easy to write and if a=matrix(1,3,4) and b=matrix(2,2,2), then adiag(a,b) would return: [,1] [,2] [,3] [,4] [,5]
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
2004 Sep 15
6
Bessel function
Dear all Currently, I'm implementing the generalized hyperbolic distribution into Splus. Unfortunately the Bessel function is not implemented in Splus. In R the Bessel function does exist but it is an internal function and I'm not able to look at the code. Is there any possibility to see the code of the Bessel function in R or does anybody has an implementation of the Bessel function in