similar to: mapply & assign to generate functions

Displaying 20 results from an estimated 10000 matches similar to: "mapply & assign to generate functions"

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
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
2003 Oct 07
3
FW: Optimising code
>> I have a function that applies a wilcoxon test to 12 sets of about a quarter of a million pairs > ... and let me guess: everything is significiant to an almost arbitrary > value of \alpha? :-) For each of quarter of a million sets, I do a wilcoxon between two pairs each containing twenty numbers... I do this 12 times... > > (and takes about 3 hours). I've replaced the
2011 Apr 16
1
Matching Problem: Want to match to data.frame with inexact matching identifier (one identifier has to be in the range of the other).
Hello R-Community, I have the following matching problem: I have two data.frames, one with an observation every month (per company ID), and one with an observation every quarter (per company ID; note that quarter means fiscal quarter; therefore 1Q = Jan, Feb, Mar is not necessarily correct and also, a fiscal quarter is not necessarily 3 month long). For every month and company, I want to get the
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)
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
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
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
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 >
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 would be greatly appreciated. Xj, Yj, and Wj are also lists, and s2,
2003 Oct 07
1
Optimising code
Hi, Does anyone have any advice on speeding up R functions (short of re-implementing them in C :-) )? I have a function that applies a wilcoxon test to 12 sets of about a quarter of a million pairs (and takes about 3 hours). I've replaced the inner loop I had originally with a function call via mapply, and also considered different approximations of the wilcoxon, rather than that which is
2007 Nov 08
2
mapply, coxph, and model formula
Hello - I am wanting to create some Cox PH models with coxph (in package survival) using different datasets. The code below illustrates my current approach and problem with completing this. ### BEGIN R SAMPLE CODE ############################## library(survival) #Define a function to make test data makeTestDF <- function(n) { times <- sample(1:200, n, replace = TRUE) event
2006 Mar 14
1
R CMD check: problems possibly from mapply?
Dear expeRts, I am trying to wrap up a package "utilities" (for my internal use). After adding a function datNAtreat that uses mapply, R CMD check gives WARNINGs for "S3 generic/method consistency", "checking replacement functions" and?"checking foreign function calls", all of which are accompanied by the following error message: Error in .try_quietly
2013 Jun 11
1
mapply on multiple data frames
Hi all- I am wondering about using the mapply function to multiple data frames. Specifically, I would like to do a t-test on a subset of multiple data frames. All data frames have the same structure. Here is my code so far: f<-function(x,y) { test<-t.test(x$col1[x$col3=="num",],v$col2[x$col3=="num",],paired=T,alternative="greater") out<-test$p.value
2011 Feb 03
1
mapply question (?)
Hi, I have a function myFun which I want to call multiple times, using different argument lists. myFun("v1", "2009", 1) myFun("v2", "2008", 1) myFun("q", "2001") How can I easily do this in R? Should I use mapply? I unsuccessfully tried something like: x <- list(c("v1", "2009", 1), c("v2",
2012 Oct 30
1
mapply instead for loop
Hi all!   My question in about using mapply instead for loop. Below is a example with for loop: Is it posible to give same results with mapply function?   Thanks for help!   OV   x <- 1:10 y <- 1:10 xyz <- data.frame(expand.grid(x,y)[1], expand.grid(x,y)[2], z = rnorm(100)) names(xyz) <- c("x", "y", "z") head(xyz) size <- 2 output <- NULL   ### for
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
2011 Nov 14
1
mapply then export
To use the gauss.quad function: gauss.quad(n,type) which returns two lists $nodes and $weights whose length will each equal n. I'd like to do this for n=1 to 40 (type will not change) and have a dataset with 40 rows and 81 columns with all the nodes and weights. The first record would have N1 and W1 only and N2--N40 and W2--W40 would be missing. The last record would be full. I've
2004 Apr 08
1
Why are Split and Tapply so slow with named vectors, why is a for loop faster than mapply
First, here's the problem I'm working on so you understand the context. I have a data frame of travel activity characteristics with 70,000+ records. These activities are identified by unique chain numbers. (Activities are part of trip chains.) There are 17,500 chains. I use the chain numbers as factors to split various data fields into lists of chain characteristics with each element of