similar to: writing function ( 'plot' and 'if') problem

Displaying 20 results from an estimated 300 matches similar to: "writing function ( 'plot' and 'if') problem"

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
2012 Mar 23
3
R numerical integration
Hi all, Is there any other packages to do numerical integration other than the default 'integrate'? Basically, I am integrating: integrate(function(x) dnorm(x,mu,sigma)/(1+exp(-x)),-Inf,Inf)$value The integration is ok provided sigma is >0. However, when mu=-1.645074 and sigma=17535.26 It stopped working. On the other hand, Maple gives me a value of 0.5005299403. It is an
2005 Dec 14
2
The fastest way to select and execute a few selected functions inside a function
Dear useRs? I have the following problem! I have a function that calls one or more functions, depending 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
2018 May 03
2
Calling the curve function with a character object converted into an expression
Hi, Down a cascade of function calls, I want to use the curve function with an expression 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 <-
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
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
2018 May 03
0
Calling the curve function with a character object converted into an expression
Sebastian: This is somewhat arcane, perhaps even a bug (correction on this welcomed). The problem is that the "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()
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(" ",
2018 May 03
1
Calling the curve function with a character object converted into an expression
Typo: should be NULL not NUL of course An alternative approach closer to your original attempt is to use do.call() to explicitly evaluate the expr argument: w <- "1 + x^2" do.call(curve, list(expr = parse(text = w), ylab ="y")) Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus
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
2010 Dec 01
3
RFC: sapply() limitation from vector to matrix, but not further
sapply() stems from S / S+ times and hence has a long tradition. In spite of that I think that it should be enhanced... As the subject mentions, sapply() produces a matrix in cases where the list components of the lapply(.) results are of the same length (and ...). However, it unfortunately "stops there". E.g., if you *nest* two sapply() calls where the inner one produces a matrix, very
1999 Jan 16
1
Core dump on sapply misuse
Developers: I hope this is the appropriate place to 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)
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
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.
2012 May 16
3
triangular matrices input/output
Hi, Is there any package that deals with triangular matrices? Say ways of inputting an upper (lower) triangular matrix? Or convert a vector of length 6 to an upper (lower) triangular matrix (by row/column)? Thanks! ----- ###################### PhD candidate in Statistics Big R Fan Big LEGO Fan Big sTaTs Fan ###################### -- View this message in context:
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
2024 Jan 11
4
arrow on contour line
Hello, I am drawing contour lines for a function of 2 variables at one level of the value of the function and want to include a small arrow in any direction of increase of the function. Is there some way to do that? Below is an example that creates the contour lines. How do I add one small arrow on each line in the direction of increase of the function (at some central point of the contour
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
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
2011 Sep 11
2
how to quote "factors" in a function?
### code ### x=sample(LETTERS[1:26],100,T) prob=function(y){ count=sum(x==y) total=length(x) count/total } ### end ### How do I quote the letters A,B,C,D ect, in order to make the "prob" function return the weights of the desired Letter? Thanks! -- View this message in context: