search for: myfunc

Displaying 20 results from an estimated 188 matches for "myfunc".

Did you mean: myfun
2010 Mar 31
2
Simplifying particular piece of code
Hello, everyone I have a piece of code that looks like this: mrets <- merge(mrets, BMM.SR=apply(mrets, 1, MyFunc, ret="BMM.AV120", stdev="BMM.SD120")) mrets <- merge(mrets, GM1.SR=apply(mrets, 1, MyFunc, ret="GM1.AV120", stdev="GM1.SD120")) mrets <- merge(mrets, IYC.SR=apply(mrets, 1, MyFunc, ret="IYC.AV120", stdev="IYC.SD120")) mrets <- mer...
2012 Jul 20
3
Execute a function
Hi, I would like to evaluate a function, with 3 arguments, for instance, myfunc<-function(a,b,c) { sqrt(a)-exp(b)+4*c } How to execute myfunc(x,y,z), for all x, all y and all z, where x,y,z are vectors? Thank you very much in advance -- View this message in context: http://r.789695.n4.nabble.com/Execute-a-function-tp4637...
2004 Sep 09
4
scoping rules
Can someone help me with this simple example? sq <- function() { y <- x^2 y } myfunc <- function() { x <- 10 sq() } myfunc() executing the above in R yields: > myfunc() Error in sq() : Object "x" not found I understand that R's scoping rules cause it to look for "x" in the environment in which "sq" was defined (the global environment...
2012 Aug 29
5
Extracting the name of a function (inverse of match.fun("myFun"))
Hi all, is there a way to extract the name of a function, i.e. do the reverse of match.fun applied to a character string? I would like to print out the name of a function supplied to another function as an argument. For example: myFunc = function(x) { x+1 } applyFunc = function(fnc, x) { fnc = match.fun(fnc) fnc(x) } Is there a way to obtain "myFunc" from the argument fnc in applyFnc the following call is issued? applyFnc(myFunc, 1) Thanks, Peter
2006 Nov 09
3
function
R-help, I am trying to create a function that i pass a data set to and have the function return some calculations based on data. Allow me to illustrate: myfunc <- function(lst,mn,sd){ lst <- sort(lst) mn <- mean(lst) sd <- sqrt(var(lst)) return(lst,mn,sd) } data1 <-c (1,2,3,4,5) data2 <- c(6,7,8,9,10) myfunc(data1,data1mn,data1sd) myfunc(data2,data2mn,data2sd) This snippet errors that data1mn not find and warns that retur...
2011 Jan 10
2
Integration in R
...nd then try to understand how integration works. Thus I am doing some first 'experiments' and I would like to request your help and comments. I have the function: p2<-function(x){0.5*(3*x^2-1)} # I found the square of p2 by using some pencil and paper. # The result is inside myfunc below myfunc<- function(x) {0.25*(9*x^4+6*x^2+1)} # Below I made R to find the square of p2 p2sq<-function(x) {p2(x) * p2(x)} # Now I am trying to integrate both two function at the same interval. #Both functions should denote the square of p2 integrate(p2sq,-1,+1) # returns 0.4...
2011 Feb 18
1
debugger() fails if "..." in function arguments
...nown problem with a workaround, or do I log it as a new problem? The situation is that if I use "options(error=dump.frames)" and then use "debugger()", it fails if there's "..." in the function arguments. Repro and version info below. Thanks, Charlie Roosen > myFunc <- function(a,b,...) {d <- a+b; stop("")} > options(error=dump.frames) > myFunc(1,2) Error in myFunc(1, 2) : > debugger() Message: Error in myFunc(1, 2) : Available environments had calls: 1: myFunc(1, 2) 2: stop("") Enter an environment number, or 0 to exit...
2007 Jun 30
1
"R CMD INSTALL in R 2.5.1 (2007-06-27)"
Hello, I'm moving from R 2.2.1 (Winows XP) to R 2.5.1 and have problems with installing "myfuncs", which worked OK in 2.2.1 R CMD INSTALL myfuns # gives installing to '' ---------- Making package myfuncs ------------ adding build stamp to DESCRIPTION installing R files installing man source files installing indices installing help >>> Building/Updating help...
2002 May 06
3
Using Object's Name in Function
Hi, Suppose I have a function: myfunc <- function(x, y) { ... } And within the function I want to print out the name of the x, y vectors. For example, if I do: > myfunc(foo, goo) [1] "foo" "goo" It shall return "foo", "goo" (with or without quotes is fine), where foo and goo are two vec...
2003 Sep 16
7
Retrieve ... argument values
Dear R users, I want to retrieve "..." argument values within a function. Here is a small exmaple: myfunc <- function(x, ...) { if (hasArg(ylim)) a <- ylim plot(x, ...) } x <- rnorm(100) myfunc(x, ylim=c(-0.5, 0.5)) Error in myfunc(x, ylim = c(-0.5, 0.5)) : Object "ylim" not found > I need to retrieve values of "ylim" (if it is defined when function is cal...
2013 Apr 29
3
Function for Data Frame
...get my function to apply its results to the data frame in question instead of simply displaying the results to the screen? Any helpful guidance would be most appreciated. --John Sparks x=as.data.frame(matrix(c(1,2,3, 1,2,3, 1,2,2, 1,2,2, 1,1,1),ncol=3,byrow=T)) myfunc<-function(DF){ DF<-subset(DF,select=-c(V1)) return(DF) } myfunc(x) #How to get this change to data frame x? #And preferrably not send the results to the screen? x
2002 Aug 03
2
variable scope
Dear R-guRus: I would like to pass variables to a function in R in "by reference", e.g Fortran style. For example, suppose I have the following code x<-c(1:10) y<-1 MyFunc<-function(x,y) {y<-sum(x); return(NULL)} MyFunc(x,y) print(y) in this case print(y) will produce "1" instead of 55 (which is sum(x)) - how do I make sure that afte the function is run, y remembers the value that was given to it within a function ???? Of course I could always do...
2002 Aug 03
2
variable scope
Dear R-guRus: I would like to pass variables to a function in R in "by reference", e.g Fortran style. For example, suppose I have the following code x<-c(1:10) y<-1 MyFunc<-function(x,y) {y<-sum(x); return(NULL)} MyFunc(x,y) print(y) in this case print(y) will produce "1" instead of 55 (which is sum(x)) - how do I make sure that afte the function is run, y remembers the value that was given to it within a function ???? Of course I could always do...
2016 May 17
3
External function resolution: MCJIT vs ORC JIT
...atTy (Context); llvm::Type* one_float[] = { type_float }; llvm::FunctionType *functype_ff = llvm::FunctionType::get (type_float, one_float, false); llvm::Function::Create (functype_ff, llvm::Function::ExternalLinkage, "sqr", M.get()); // Create myfunc and generate its IR, which just calls sqr on its argument llvm::Function *myfunc = llvm::Function::Create (functype_ff, llvm::Function::ExternalLinkage, "myfunc", M.get()); ll...
2002 Aug 06
1
re| `By reference'
David Brahm <brahm at alum.mit.edu> wrote: >VBMorozov at lbl.gov wrote: >> I would like to pass variables to a function in R in "by reference"... >Just in case the ensuing discussion got too esoteric, here's one simple answer: >R> x <- 1:10 >R> MyFunc <- function(x, zz) assign(deparse(substitute(zz)), sum(x), 1) >R> MyFunc(x,y) >R> y > [1] 55 Still less esoteric is > MyFunc <- function(x,zz) zz <<- sum(x) > MyFunc(1:10,y) > y [1] 55 Although I don't know if this is a good general solution to `passing...
2009 Aug 06
1
Using 'field names' of a data.frame in a function
...data.frame ( ages=c('40-49','40-49','40-49','30-39','50-59','50-59','60-69','50-59'), sex = c("M","F","F","M","F","F","M","M")) #build a simple function myfunc <- function (categories) { table (categories) } #call the function myfunc (c(mydataset$ages, mydataset$sex)) === My output I am getting is: categories 1 2 3 4 5 7 3 1 But what I'm expecting is: table (mydataset$ages, mydataset$sex) F M 30-39 0 1 40-49 2 1 50-59 2 1 6...
2008 Mar 27
1
A faster way to compute finite-difference gradient of a scalar function of a large number of variables
...d <- function(x, fn=func, eps=1.e-07, ...){ npar <- length(x) df <- rep(NA, npar) f <- fn(x, ...) for (i in 1:npar) { dx <- x dx[i] <- dx[i] + eps df[i] <- (fn(dx, ...) - f)/eps } df } myfunc <- function(x){ nvec <- 1: length(x) sum(nvec * (exp(x) - x)) / 10 } myfunc.g <- function(x){ nvec <- 1: length(x) nvec * (exp(x) - 1) / 10 } p0 <- rexp(1000) system.time(g.1 <- grad(x=p0, fn=myfunc))[1] system.time(g.2 <- myfunc.g(x=p0))[1] max(abs(g.2 - g.1))...
2009 Apr 07
2
Puzzled by an error with apply()
I've written a function, myFunc, that works fine with myFunc(data, ...), but when I use apply() to run it with an array of data apply(myArray, 1, myFunc, ...) I get a strange error: Error in match.fun(FUN) : '1' is not a function, character or symbol which really puzzles me because '1' is meant to be the margi...
2006 Jun 15
4
Yahoo!-like Event object emulation/abstraction in Prototype?
Hi, I was reading about the Yahoo! library recently and was really excited by the idea that I wouldn''t have to branch for IE in my event handlers. Is there any chance that such abstraction will come to Prototype? Thanks, Sam
2007 May 09
3
Increasing precision of rgenoud solutions
Dear All I am using rgenoud to solve the following maximization problem: myfunc <- function(x) { x1 <- x[1] x2 <- x[2] if (x1^2+x2^2 > 1) return(-9999999) else x1+x2 } genoud(myfunc, nvars=2, Domains=rbind(c(0,1),c(0,1)),max=TRUE,boundary.enforcement=2,solution.tolerance=0.000001) How can one increase the precision of the solution $par [1] 0.7072442...