similar to: transform input argument (matrix) of function

Displaying 20 results from an estimated 10000 matches similar to: "transform input argument (matrix) of function"

2012 Nov 20
2
correct function formation in R
Dear list! ? I have question of?'correct function formation'. Which function (fun1 or fun2; see below) is written more correctly? Using ''structure'' as output or creating empty ''data.frame'' and then transform it as output? (fun1 and fun1 is just for illustration). ? Thanks a lot, OV ? code: input <- data.frame(x1 = rnorm(20), x2 = rnorm(20), x3 =
2006 Aug 09
3
objects and environments
Dear list, I have two functions created in the same environment, fun1 and fun2. fun2 is called by fun1, but fun2 should use an object which is created in fun1 fun1 <- function(x) { ifelse(somecondition, bb <- "o", bb <- "*") ## mymatrix is created, then myresult <- apply(mymatrix, 1, fun2) } fun2 <- function(idx) { if (bb == "o) { #
2012 Nov 07
1
row index for max values of row groups
Dear list members! I am looking for ''nice solution'' for (maybe) simple problem. I need a code (small program) to calculate row index for max value (example below: df1$values) by groups (example below: df1$groups). df1 <- data.frame( groups = c(1,1,1,1,1,2,2,2,3,3,3,3), values = c(1,1,1,2,1,1,2,3,2,1,4,3) ) df1 expected results > 4 8 11 # row index of max values by group
2004 Mar 25
1
mlocal/mtrace inside a loop
Hello I need some help in figuring Bravington’s debugger out. Ok I have 2 functions, fun1 and fun2 saved in a ASCII file say filename is funs. Fun1 has a loop which calls fun2, fun2 has a loop which fails and I need to find out the value of the variables of the fun2 and fun1 loops at the specific iteration that fails. Both fun1 and fun2 loops will iterate thousands of times so line by line debug
2011 Apr 07
2
Two functions as parametrs of a function.
Hi R users: I'm trying to make a function where two of the parameters are functions, but I don't know how to put each set of parameters for each function. What am I missing? I try this code: f2<-function(n=2,nsim=100,fun1=rnorm,par1=list(),fun2=rnorm,par2=list()){ force(fun1) force(fun2) force(n) p1<-unlist(par1) p2<-unlist(par2) force(p1) force(p2)
2009 Oct 01
1
pass "..." to multiple sub-functions
Dear list, I know I have seen this discussed before but I haven't been successful in searching for "ellipsis", "dots", "..." in the archives. I would like to filter "..." arguments according to their name, and dispatch them to two sub-functions, say fun1 and fun2. I looked at lm() but it seemed more complicated than I need as it modifies the calling
2012 Aug 30
1
How to modify the values of the parameters passing via ...
Dear Friends, Let's assume there are three parameters that were passed into fun1. In fun1, we need to modify one para but the remains need to be untouched. And then all parameters were passed into fun2. However, I have failed to achieve it. Please see the following code. ########################################## fun1 <-function(x, y, z=10) {x+y+z;} fun2 <-function(aa, ...) {
2014 Jan 25
1
package NAMESPACE question
Hello, I'm building a package. My code is stored in foo.R. This code has two functions FUN1 and FUN2. FUN1 calls FUN2. FUN1 is listed in export() under the package NAMESPACE but NOT FUN2. After building the package when I call FUN1 is giving me an error that cannot find FUN2. I solved this by adding FUN2 in the export() NAMESPACE. However, what is puzzling me is that I have other examples
2006 Aug 16
1
Problem with the special argument '...' within a function
I'm not sure if this is what you want, but simply add ... to the list of arguments for fun1 and fun2 would eliminate the error. Andy From: Hans-Joerg Bibiko > > Dear all, > > I wrote some functions using the special argument '...'. OK, it works. > > But if I call such a function which also called such a > function, then I get an error message about unused
2009 May 01
1
integrate with large parameters
Dear R-users, i have to integrate the following function `fun1` <- function (a, l1, l2) { exp(log(l1) * (a - 1) - l2 * lgamma(a)) } but if l1 is large, i get the "non-finite function value" error, so my idea is to rescale with exp(-l1) `fun2` <- function (a, l1, l2) { exp(log(l1) * (a - 1) - l2 * lgamma(a) - l1) } but it seems this doesn't solve the problem, when
2009 Jun 16
1
ifelse(is.na), with function inside
Hi, I have a vector a=c(NA, 3, 4, 4, NA, NA, 3) and I would like to use is.na(a) function to get a vector like this: wy=(1,2,2,2,1,1,2) - you know, this vector create 1 or 2 depends on value in vector "a" This is my short code but something is wrong and I don't know what... for (i in 1:7){ a=c( NA, 3, 4, 4, NA, NA, 3) fun1=function(x){ x=1 print(x) } fun2=function(x){
2017 Apr 30
1
`match.call` and dots substitution
I'm noticing some interesting behavior in `match.call` in some corner-ish cases that arise when you try to use `match.call` to match a "grandparent" function and there are dots involved: fun0 <- function(a, ...) fun1(...) fun1 <- function(b, ...) fun2() fun2 <- function() match.call( fun1, sys.call(sys.parent()), expand.dots=FALSE,
2010 Aug 11
2
storing the results of an apply call
Hi R-users, I have a function (myfun) that I want to apply to the rows of a matrix. Basically, "myfun" takes the values from the matrix ("exp.des"), which represent the different combinations of my experimental design, and pass them as arguments to some other functions (fun1 and fun2). As I want to replicate the results of fun1 and fun2 a certain number of time (e.g. 5), I
2015 Feb 26
1
iterated lapply
> On Feb 25, 2015, at 5:35 PM, Benjamin Tyner <btyner at gmail.com> wrote: > > Actually, it depends on the number of cores: Under current semantics, yes. Each 'stream' of function calls is lazily capturing the last value of `i` on that core. Under Luke's proposed semantics (IIUC), the result would be the same (2,4,6,8) for both parallel and serial execution. This is
2012 Dec 15
3
kruskalmc, significant differences while median values are the same
Dear list! I work with multiple Kruskal-Wallis test (kruskalmc, package pgirmess), which evaluates differences in medians among groups (5 groups). A result of a test is significant differences among some groups, while median values are the same for 4 groups (using tapply). Why? p.s.: number of samples in groups vary from 50 to 4900. Thanks to all, OV .
2004 Mar 23
3
how to modify variables of another frame (but not global)
Hello! Maybe "frame" is not the right term in this context. I explain my problem by example code: fun2 <- function(objName, add) { ## the object "objName" should be increased by "add", ## but the evaluation should be done in the calling function (here: fun1) ## ...... what's the right code?? } fun1 <- function() { x <- 1 fun2("x",
2012 Apr 15
1
match values from data.frame and vector
Dear R helpers! I have a vector 'x1' and data.frame 'df1'. Do you have any suggestion how to get vector x2, which will be a result of matching values from vector 'x1' and values from 'df1'? Please, see the example: x1 <- c(rep(1,3), rep(NA,2), rep(2,4)) df1 <- data.frame(c1 = c(1,2), c2 = c(5,6)) I would like to get vector x2: > x2 [1]  5  5  5 NA NA  6 
2007 Nov 26
1
Preserving output of MCMC iterations
Dear colleagues, I'm an epidemiologist with no background in programming and just started using R a few weeks ago. I am working on the epidemiology of African sleeping sickness, and am trying to use R to perform a Monte Carlo Markov Chain analysis to estimate three unknown parameters within a model of African sleeping sickness case detection that is mainly informed by actual field programme
2011 Nov 18
2
round() ignores missing arguments if it is used inside another function where some arguments are missing.
I have stumbled across some behaviour in R that I really can't place, and that makes coding a bit tricky. I know that I can work around it when explicitly checking for missing arguments, but still... I have two functions. I have a first function based on paste ? ? fun1 <- function(x,y){ ? ? ? print(missing(y)) ? ? ? paste(x,'X',sep=y) ? ? } If I try this function without
2020 May 02
1
issues with environment handling in model.frame()
Dear all, model.frame behaves in a way I don't expect when both its formula and subset argument are passed through a function call. This works as expected: model.frame(~wool, warpbreaks, breaks < 15) #> wool #> 14 A #> 23 A #> 29 B #> 50 B fun1 <- function(y) model.frame(~wool, warpbreaks, y) fun1(with(warpbreaks, breaks < 15)) #> wool #> 14