Displaying 20 results from an estimated 667 matches for "mapply".
Did you mean:
apply
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...
2011 Feb 02
2
Help me apply mapply
Hello all I would like to ask your help use mapply.
I have a function called findCell that takes two arguments(x,sr)
where x is a vector of size two (e.g x<-c(2,3) and sr is a matrix.
I would like to call many times the findCell function (thus I need mapply) for different x inputs but always for the same sr.
as x is a vector of size two (two...
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)...
2013 Dec 06
2
Using assign with mapply
...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 this is what I get:
: mapply(assign, kkk$vars, kkk$vals)
var1 var2 var3
10 20 30
: var2
Error: object 'var2' not found
Maybe I have not undestand how mapply and assign work. Do you have
any comments?
Thanks,
-Sergio.
2008 Mar 23
1
mapply
...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 one
below.
I think I understand mapply a little but what I don't understand how
it knows to take the rows of rawdata and then I guess recycle sens ?
how did the mapply know not to take the columns of rawdata and do
something to them ? or maybe mapply does things element by element and it is
doing more
complex recycling ? I gu...
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 gener...
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 speed) than the for loop. Here is an example....
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)...
2009 Jan 06
5
Using apply for two datasets
I can run one-sample t-test on an array, for example a matrix myData1,
with the following
apply(myData1, 2, t.test)
Is there a similar fashion using apply() or something else to run
2-sample t-test with datasets from two groups, myData1 and myData2,
without looping?
TIA,
Gang
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...
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) {...
2009 Jun 03
1
Vectorize fails for function with ... arglist
Vectorize is defined to return a function that acts as if 'mapply' was
called.
So we have:
> mapply(dput,1:2) # mapply form
1L # calls dput on each element of 1:2
2L
[1] 1 2
> Vectorize(dput)(1:2) # Vectorize form
1L # same behavior
2L
[1] 1 2
Same thing wit...
2007 Nov 08
2
mapply, coxph, and model formula
...data of different sizes
testdf1 <- makeTestDF(100)
testdf2 <- makeTestDF(200)
#Define a formula and call coxph
form <- Surv(times, event) ~ trt
coxph(form, testdf1) #Works
coxph(form, testdf2) #Works
#Create a list of the two data.frames
df.list <- list(testdf1, testdf2)
#Try to use mapply
mapply(coxph, form, df.list)
### END R SAMPLE CODE ###############################
The mapply call generates the following message:
Error in terms.default(formula, special, data = data) :
no terms component
It appears from debugging that the formula argument passed into coxph is
simply `~` in...
2017 Sep 28
3
building random matrices from vectors of random parameters
Thanks for both the mapply and array approaches! However, although
intended to generate the same result, they don't:
# mapply approach
n = 3
sa <- rnorm(n,0.8,0.1)
so <- rnorm(n,0.5,0.1)
m <- rnorm(n,1.2,0.1)
mats = mapply(function(sa1, so1, m1)
matrix(c(0,sa1*m1,so1,sa1),2,2,byrow=T), sa, so, m, SIMPLIFY =...
2005 Nov 20
1
mapply() gives seg fault (PR#8332)
--KsGdsel6WgEHnImy
Content-Type: text/plain; charset=iso-8859-1; format=flowed
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
Hi, people. Wandering in R archives, and seeing the message attached
below, I noticed that:
mapply(rep,times=1:4, MoreArgs=42)
still segfaults on R 2.2.0, and thought I should be a good citizen and
report it, even if I do not have an actual problem with this. :-)
> version
_
platform i686-pc-linux-gnu
arch i686
os linux-gnu
system i...
2006 Sep 03
3
Merge list to list - as list
...t;- list(list(c(1, -1, -1, 1, 1),c(1, 1, -1, -1, -1)),
list(c(1, 1, 1, 1, 1),c(1, 1, -1, 1, -1)))
x
y
#I need merge x and y, I have tried with
list.uni <- vector("list", length(x))
for (i in 1:length(x)) {
for (j in 1:length(x[[1]])) {
list.uni[[i]][[j]] <- mapply(cbind,
x[[i]][[j]],
y[[i]][[j]],
SIMPLIFY=FALSE)
}
}
list.uni
I have learn about ?lapply, ?sapply and ?mapply but I still didn't
understand how to use it.
I need the result...
2009 Oct 14
1
using mapply to avoid loops
Hello, I would like to use mapply to avoid using a loop but for some reason, I can't seem to get it to work. I've included copies of my code below. The first set of code uses a loop (and it works fine), and the second set of code attempts to use mapply but I get a "subscript out of bounds" error. Any guidance woul...
2012 Nov 15
0
R-devel Digest, Vol 117, Issue 13
Hi,
> ... Wrong. It looks like internally a[[1]] is always used instead of a[[i]].
> The real problem it seems is that 'a' is treated as if it was of
> ength 1:
>
> > mapply(function(x, y) {x * y}, a, 1:3)
> [1] 101 202 303
> > mapply(function(x, y) {x * y}, a, 5)
> [1] 505
>
> In other words, internal dispatch works for [[ but not for length().
Documentation of mapply says
> Arguments are recycled if necessary.
So, the function seems to wo...
2007 Jan 23
3
Matrix operations in a list
..., ncol=5), matrix(rnorm(50), ncol=5))
b <- list(matrix(rnorm(50), nrow=5), matrix(rnorm(50), nrow=5))
I don't recall how to perform matrix multiplication on each list element
such that the result is a new list
result <- list(a[[1]]%*%b[[1]], a[[2]]%*%b[[2]])
I think I'm close with mapply(), but I'm doing something silly
mapply('%*%', a,b)
Thanks.
Harold
[[alternative HTML version deleted]]
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