similar to: Help me apply mapply

Displaying 20 results from an estimated 20000 matches similar to: "Help me apply mapply"

2006 Jul 20
2
Timing benefits of mapply() vs. for loop was: Wrap a loop inside a function
List: Thank you for the replies to my post yesterday. Gabor and Phil also gave useful replies on how to improve the function by relying on mapply rather than the explicit for loop. In general, I try and use the family of apply functions rather than the looping constructs such as for, while etc as a matter of practice. However, it seems the mapply function in this case is slower (in terms of CPU
2013 Nov 01
2
computation of hessian matrix
below is a code to compute hessian matrix , which i need to generate 29 number of different matrices for example first element in x1 and x2 is use to generate let say matrix (M1) and second element in x1 and x2 give matrix (M2) upto  matrix (M29) corresponding to the total number of observations and b1 and b2 are constant.  can some one guide me or help to implement this please. I did not
2003 May 20
2
Extending %*%
I have lists of matrices stored in various ways. I'd like to extend %*% to work on these. Is this possible, or should I create my own new operator? A simplified example would be as follows: A <- list( A1, A2, A3) B <- list( B1, B2, B3) where A1,...,B3 are all matrices, and I'd like A %*% B to return list( A1 %*% B1, A2 %*% B2, A3 %*% B3) In the real case A and B are sometimes
2007 Jul 31
5
extract columns of a matrix/data frame
Hello all, I have a matrix whose column names look like a1 a2 b1 b2 b3 c1 c2 1 2 3 7 1 3 2 4 6 7 8 1 4 3 Now, I can have any number of a's. not just two as shown above and same goes for b's and c's. I need to extract all the a's columns and put them in another matrix, extract all b's columns and put them in some matrix
2007 Oct 24
1
Error in nls model.frame
Error in model.frame When I run the following nls model an error message appears and I dont know how to solve that. Could you help me?? mat = c(1,2,3,4,5,6,7,8,9,12,16,24,36,48,60) for (i in 1:length(j30)) { bliss = nls(c(j[i,1:length(mat)]) ~ b0 + b1*((1-exp(-k1*mat))/(k1*mat)) + b2*(((1-exp(-k2*mat))/(k2*mat))-exp(-k2*mat)), start = list(k1=0.1993, k2=0.1993, b0= 22.0046,
2007 Aug 07
1
Naming Lists
Hi Im pretty new to R and I have run in to a problem. How do I name all the levels in this list. Lev1 <- c("A1","A2") Lev2 <- c("B1","B2") Lev3 <- c("C1","C2") MyList <- lapply(Lev1,function(x){ lapply(Lev2,function(y){ lapply(Lev3,function(z){ paste(unlist(x),unlist(y),unlist(z)) })})}) I would like to name the different
2012 Mar 01
3
Converting a string vector with names to a numeric vector with names
Not paying close attention to detail, I entered the equivalent of pstr<-c("b1=200", "b2=50", "b3=0.3") when what I wanted was pnum<-c(b1=200, b2=50, b3=0.3) There was a list thread in 2010 that shows how to deal with un-named vectors, but the same lapply solution doesn't seem to work here i.e., pnum<-lapply(pstr, as.numeric) or similar vapply
2015 Jan 29
2
Listas Recursivas
Hola Tengo un análisis en el que como resultado obtengo una lista recursiva, es decir, una lista cuyos componentes a su vez son listas. Son varias iteraciones de una función que proporciona varios resultados de interés de distinta naturaleza y por eso los uno en una lista. Las iteraciones son hechas en paralelo, y los resultados de una función de este tipo suelen ser empaquetados a su vez en una
2003 Oct 14
3
mapply() gives seg fault
Hello everybody. I've been experimenting with mapply(). Does anyone else have problems with: R> mapply(rep,times=1:4, MoreArgs=42) (I get a seg fault). robin R> R.version _ platform powerpc-apple-darwin6.6 arch powerpc os darwin6.6 system powerpc, darwin6.6 status beta major 1 minor 8.0 year 2003 month 10 day 02 language R >
2008 Mar 23
1
mapply
In an earlier post, a person wanted to divide each of the rows of rawdata by the row vector sens so he did below but didn't like it and asked if there was a better solution. rawdata <- data.frame(rbind(c(1,2,2), c(4,5,6))) sens <- c(2,4,6) temp <- t(rawdata)/sens temp <- t(temp) print(temp) Gabor sent three other solutions and I understood 2 of them but not the
2012 Mar 12
2
mapply & assign to generate functions
Hi, I have a problem that I'm finding a bit tricky. I'm trying to use mapply and assign to generate curried functions. For example, if I have the function divide divide <- function(x, y) { x / y } And I want the end result to be functionally equivalent to: half <- function(x) divide(x, 2) third <- function(x) divide(x, 3) quarter <- function(x) divide(x, 4) But I want
2004 Jun 15
4
"Glueing" factors together
Hi folks, Suppose I have a series of cases each with categorical factors A, B. What is the best way to "glue" A and B together into a single factor? For example, given A0 B1 ... A1 B1 ... A0 B2 ... A1 B0 ... A0 B0 ... A1 B2 ... then I'd like to end up with a single factor with levels A0B0, A0B1, A0B2, A1B0, A1B1, A1B2 according to all the combinations which actually occur in
2013 Feb 07
1
Merging data in arrays
Dear All, Here is a hypothetical sample (sorry for the clumsy code): A1 <- matrix(1:5, nrow=5, ncol=1) A2 <- matrix(6:10, nrow=5, ncol=1) A3 <- matrix(11:15, nrow=5, ncol=1) A4 <- matrix(16:20, nrow=5, ncol=1) A5 <- matrix(21:25, nrow=5, ncol=1) A6 <- matrix(26:30, nrow=5, ncol=1) B1 <- matrix(c(A1, A2, A3), nrow=5, ncol=3) B2 <- matrix(c(A2, A3, A4), nrow=5, ncol=3) B3
2012 Nov 15
1
bug with mapply() on an S4 object
Hi, Starting with ordinary vectors, so we know what to expect: > mapply(function(x, y) {x * y}, 101:106, rep(1:3, 2)) [1] 101 204 309 104 210 318 > mapply(function(x, y) {x * y}, 101:106, 1:3) [1] 101 204 309 104 210 318 Now with an S4 object: setClass("A", representation(aa="integer")) a <- new("A", aa=101:106) > length(a)
2013 Oct 25
1
add a color band
Hi all, I would like to ask your help to add a color band (Ι am not sure regarding the right term, this color band at the right of the plot "describing" values with their corresponding color. For now I have only this code test<-matrix(data=runif(10000),nrow=100) plot(test,axes="FALSE") axis(1,at=c(0,1),labels=c("a","b")) # but  I would like to add
2011 Jul 31
1
Trouble Using mapply
Dear all, I am having a problem with mapply. I guess the reason is that mapply is not "vectorized". But could you please take a look at my code below and help me to find a solution (either a better way to use mapply or a different function to call). Thanks a lot! ##beginning of my code myfun <- function(threshold, all.data) { ##Just a demostration of a function that takes a
2006 Aug 31
2
Wish: keep names in mapply() result
Hello! I have noticed that mapply() drops names in R 2.3.1 as well as in r-devel. Here is a simple example: l <- list(a=1, b=2) k <- list(1) mapply(FUN="+", l, k) [1] 2 3 mapply(FUN="+", l, k, SIMPLIFY=FALSE) [[1]] [1] 2 [[2]] [1] 3 Help page does not indicate that this should happen. Argument USE.NAMES does not have any effect here as it used only in a bit special
2013 Feb 14
1
mapply error with Math (S4 group generic)
I get an error when using self-defined (not standard) functions with mapply with S4 objects from the raster package that I develop: "Error in as.character(sys.call(sys.parent())[[1]]) : cannot coerce type 'closure' to vector of type 'character'". Does anyone understand why? The problem is illustrated below. Thanks, Robert > # First a general example that works
2013 Dec 06
2
Using assign with mapply
I have a data frame whose first colum contains the names of the variables and whose second colum contains the values to assign to them: : kkk <- data.frame(vars=c("var1", "var2", "var3"), vals=c(10, 20, 30), stringsAsFactors=F) If I do : assign(kkk$vars[1], kkk$vals[1]) it works : var1 [1] 10 However, if I try with mapply
2011 Feb 23
2
list multiplied by a factor / mapply
Dear list, this works fine: x <- split(iris, iris$Species) x1 <- lapply(x, function(L) transform(L, g = L[,1:4] * 3)) but I would like to multiply each Species with another factor: setosa by 2, versicolor by 3 and virginica by 4. I've tried mapply but without success. Any thoughts? Thanks for any idea! Patrick