Displaying 20 results from an estimated 43 matches for "myf".
Did you mean:
my
2005 Dec 14
2
The fastest way to select and execute a few selected functions inside a function
...on the input parameters. I am searching for the fastest
way to select and execute the selected functions and return their results in
a list. The number of possible functions is 10, however usually only 2 are
selected (although sometimes more, even all).
For examples, if I have function "myf" and the possible functions that I
want to call are "mean", "max" and "sum". I have thought of one way (myf) to
do that and am interested if there maybe exists a faster way (the speed is
very important, since this can be repeated millions of times in my
functi...
2018 May 03
2
Calling the curve function with a character object converted into an expression
...ression that is a variable. For various reason, this variable must be a character object and cannot be an expression as required by the curve function. How do I convert my variable into a expression that is accepted by curve?
Thanks in advance for your help.
## The following attempts do not work
myf <- '1+x^2'
curve(myf, from = 0, to = 10) # obviously !
curve(parse(text=myf), from = 0, to = 10) # not sure why this does not work
## This works but does not feel elegant:
eval(parse(text=sprintf('curve(%s, from = 0, to = 10)', myf)))
2005 Nov 23
3
Infinite recursion in S3 methods crashes R on windows (related to PR#8203?)
Hi,
Infinite recursion in S3 methods seem to crash R on Windows 2000 (R
terminating with the ("Rgui.exe has generated errors...") message,
rather than throwing an error. This happens with both Rgui and Rterm.
The following toy example triggers this:
myf <- function(x, ...)
UseMethod("myf")
myf.default <- function(x, ...)
myf(x)
myf(1)
...R crashes...
Which I would expect to terminate with the usual "evaluation nested
too deeply: infinite recursion" or protect stack overflow message.
This may be related to the repo...
2011 Feb 22
1
Discrepancies in run times
Dear R-users,
I am in the process of creating new custom functions and am quite puzzled by
some discrepancies in execution time when I run some R scripts that call
those new functions. So here is the situation:
- let's assume I have created two custom functions, called myg and myf;
- myg is mostly a plotting function, which makes a heavy use of grid and
lattice functions;
- myf is a function that massages data, opens and closes graph devices, and
pass the data to myg:
* myf contains loops and sub-loops which subset the data in little pieces
necessary for plotting purposes;...
2018 May 03
0
Calling the curve function with a character object converted into an expression
...quot;expr" argument to curve() must be
an actual expression, not a call to parse that evaluates to an
expression. If you look at the code of curve() you'll see why
(substitute() does not evaluate expr in the code). Another simple
workaround other than sticking in the eval() call is this:
myf <- function(x)NUL
body(myf)<- parse(text = "{1+x^2}") ## note the additional "{ }"
for safety, though not necessary here
## this idiom will continue to work for any text.
curve(myf, from = 0, to = 10) ## myf is now the name of a function
that executes the parsed text...
2012 Nov 06
1
how Can make function for selecting the products
HI.
I make this code:
getdata<-function('a','b','c' ,'d','e','f'){
drv <- dbDriver("SQLite")
con<-dbConnect(drv, "sqlite.db")
lt<-dbListTables(con)
myf<-data.frame(NULL)
for (i in 1:length(lt))
{
myfile<-dbReadTable(con,lt[i])
myfile1<-myfile[-c(14:44)]
myfile1$MODEL<-gsub(" ", "", myfile1$MODEL)
library(RSQLite)
library(sqldf)
my_file<-sqldf("SELECT *
FROM myfile1 where MODEL in ('a','b...
2018 May 03
1
Calling the curve function with a character object converted into an expression
...urve() must be
> an actual expression, not a call to parse that evaluates to an
> expression. If you look at the code of curve() you'll see why
> (substitute() does not evaluate expr in the code). Another simple
> workaround other than sticking in the eval() call is this:
>
> myf <- function(x)NUL
> body(myf)<- parse(text = "{1+x^2}") ## note the additional "{ }"
> for safety, though not necessary here
> ## this idiom will continue to work for any text.
>
> curve(myf, from = 0, to = 10) ## myf is now the name of a function
>...
2011 Feb 03
1
Getting variable names in function output
Dear R-users,
I would like to have some advises about a problem illustrated by the
following snippet. Within myf, I need to evaluate a piece of R code that is
passed as a character argument and then return the objects that are created
by this code. The difficulty comes from the fact that the content of the
code is variable and unknown to me (obviously not in this illustration!).
With the following script, myf...
2010 Dec 18
3
use of 'apply' for 'hist'
Hi all,
##########################################
dof=c(1,2,4,8,16,32)
Q5=matrix(rt(100,dof),100,6,T,dimnames=list(NULL,dof))
par(mfrow=c(2,6))
apply(Q5,2,hist)
myf=function(x){ qqnorm(x);qqline(x) }
apply(Q5,2,myf)
##########################################
These looks ok.
However, I would like to achieve more.
Apart from using a loop,
is there are fast way to 'add' the titles to be more informative?
that is, in the histograms, I want the titles to...
2004 Apr 05
3
Evaluation of functionals
Suppose I have
f1 <- function(x) x
f2 <- function(x) x^2
funlist <- list(f1,f2)
Then I would like to evaluate funlist such that when x is 10 I should get a list with 10 and 100.
A naive way of doint this is
myf <- funlist[[1]]
do.call(paste(quote(myf)), list(x=10))
myf <- funlist[[2]]
do.call(paste(quote(myf)), list(x=10))
- but there has to be much more elegant ways of doing this. I just can't figure out how..
Put more generally, is there a way of making R "understand" au...
2010 Dec 01
3
RFC: sapply() limitation from vector to matrix, but not further
...e inner one
produces a matrix, very often the logical behavior would be for
the outer sapply() to stack these matrices into an array of
rank 3 ["array rank"(x) := length(dim(x))].
However it does not do that, e.g., an artifical example
p0 <- function(...) paste(..., sep="")
myF <- function(x,y) {
stopifnot(length(x) <= 3)
x <- rep(x, length.out=3)
ny <- length(y)
r <- outer(x,y)
dimnames(r) <- list(p0("r",1:3), p0("C", seq_len(ny)))
r
}
and
> (v <- structure(10*(5:8), names=LETTERS[1:4]))
A B C D
5...
1999 Jan 16
1
Core dump on sapply misuse
...o post this request.
I am getting a core dump in an application of sapply. A
simplified example is the following. Because simplify=TRUE
is the default for sapply and tapply, the following works
x <- 1:5; sapply(x,list)
but the following dumps core with an access violation
x <- 1:5; myf <- function(x) list(x,x); sapply(x,myf)
I am running R version 0.63.1 under Windows NT 4.00 (p.s.
and am also experiencing the 'impossible to access
clipboard' problem with graphics under NT but not under
Win95).
Could a gentler message be encoded (e.g. a check after the
call to l...
2003 Jul 30
2
Plotting a function with curve()
Why does
> curve(function(y) y^2, from=0,to=1)
not work, whereas
> myf <- function(y) y^2
> curve(myf, from=0,to=1)
work?
For the former, I get the error message
Error in curve(function(y) y^2, from = 0, to = 1) :
'expr' must be a function or an expression containing 'x'
I'm using R1.7.0 under Windows XP.
Damon Wischik.
2006 Dec 14
1
Reverse order of grouping factor in grouppedData
I created the following groupedData object (nlme library):
gd <- groupedData(Conc ~ Time | Subj,
order.groups=T,
FUN = myf,
data=mydata)
The idea of the myf function is to reverse the order of the grouping factor
Subj (or better, reorder from largest to smallest). In the mydata data set,
Subj is an integer that gets converted into a factor in the groupedData
object.
Does anyone knows how to write this function myf...
2010 Apr 13
3
writing function ( 'plot' and 'if') problem
===========================
myf=function(ds=1){
x=rnorm(10)
y=rnorm(10)
{ #start of if
if (ds==1)
{
list(x,y)
}
else (ds==2)
{
plot(x,y)
}
} # end of if
} # end of function
===========================
Hi All,
the problem i am having here is,
that I want to be able to control the display,
lf ds=1, i want to just have a list,...
2024 Jan 11
4
arrow on contour line
...of the function (at some
central point of the contour line)? Any direction will do, but perhaps the
direction of the gradient will be the best.
Thanks in advance.
DB
--------------------------------------------
library(tidyverse)
x <- seq(1,2,length.out=100)
y <- seq(1,2,length.out=100)
myf <- function(x,y) {x*y}
myg <- function(x,y) {x^2 + y^2}
d1 <- expand.grid(X1 = x, X2 = y) %>%
mutate(Z = myf(X1,X2)) %>%
as.data.frame()
d2 <- expand.grid(X1 = x, X2 = y) %>%
mutate(Z = myg(X1,X2)) %>%
as.data.frame()
ggplot(data = d1, aes(x=X1,y=X2,z=Z))+
stat_...
2011 May 23
2
Passing function arguments to dataset names
Hello,
I am stuck in a relatively simple procedure and was wondering if anybody
knows the answer. I am a relatively new R user.
How do I use an argument of a custom function in the name of a dataset in R?
For example, I have the function:
MyF <- function(Tic, price){
xxxxx
xxxxx
xxxxx
Ratio.Tic<- SharpeRatio.annualized(roc)
}
I would like to have a dataset that's labelled Ratio.MSFT, Ratio.XOM,
Ratio.IBM...etc. The objective is to append multiple Ratio.Tic datasets that
cont...
2006 Aug 21
1
Escaping " ' " character
...ear all:
I have a character object x with ' (single-quote)
character.
x <- c('"hydrolase activity","actin
binding","3',5'-cyclic-nucleotide phosphodiesterase
activity")
I want to write a function that will identify ' and
replaces with \'
myf <- function(term){
if (grep("'",term))
{ sub("'","\'",term)}
}
> myf(x)
[1] "hydrolase activity"
[2] "actin binding"
[3] "3',5'-cyclic-nucleotide phosphodiesterase
activity"
In the result "3',5'&qu...
2007 Dec 14
1
Function built with segments
Hello,
I'm new to R. If I have a set of 10 points (X(i), Y(i)), is there an elegant
way to build a function y=f(x) that would be build out of the consecutive
segments of X(j),Y(j) points (with X(j) sorted)?
Thank you very much
TDB
--
View this message in context: http://www.nabble.com/Function-built-with-segments-tp14337780p14337780.html
Sent from the R help mailing list archive at
2012 Apr 18
0
Numerical integration again
...ls when j=7,
ie
> myint(7)
Error in integrate(f, xa, xb, subdivisions = 512, rel.tol = tol) :
the integral is probably divergent
All other values from 0 to 20 works fine.
I have even plotted the graph (when j=0:20), most only has a single 'peak',
close to 0 however.
> j=7
> myf=function(x){
> (1/(1+exp(-x)))^j*(1-1/(1+exp(-x)))^(k-j)*dnorm(x,mu,casigma) }
> plot(-3:3,myf(-3:3))
> myf(-2)
[1] 1.053024e-07
I just wonder why it does not work when j=7. It could at least give me a
value 1.053024e-07, instead of an error.
> integrate(myf,-Inf,Inf)
0 with absolute...