[R] writing function : can't find an object

2010-05-26 Thread arnaud Gaboury
Dear group, Here is my function: #return the daily PL for day y PLDaily-function(x,y) { #find elements in my directory with LSCPos in the name, keep the numeric part in the name and #create a list l-gsub(\\D,,dir()[grep(LSCPos,dir())]) #select in the list the desired elements

Re: [R] writing function : can't find an object

2010-05-26 Thread Peter Ehlers
On 2010-05-26 1:17, arnaud Gaboury wrote: Dear group, Here is my function: #return the daily PL for day y PLDaily-function(x,y) { #find elements in my directory with LSCPos in the name, keep the numeric part in the name and #create a list l-gsub(\\D,,dir()[grep(LSCPos,dir())]) #select

Re: [R] writing function : can't find an object

2010-05-26 Thread Ivan Calandra
Hi, The first problem (I think) is your for loop: for (i in sel), what is sel?! Then you might want to write position[i] and trade[i] (I don't think that position and trade are functions, or they are in a package you don't specify). Depending on the class of position and trade, you might

[R] writing function

2010-05-24 Thread arnaud Gaboury
Dear group, Here is my environment after I run a function, myfun() myfun() ls() [1] allconavprix16 DailyPL100416 DailyPL100419 DailyPL100420 l llmyl PL PLdaily PLglobal PLmonthly [13] Pos100415 Pos100416 Pos100419

Re: [R] writing function

2010-05-24 Thread Joshua Wiley
My guess is that either ls(), called inside grep() or mget() is looking in an environment you do not want it to. When you create a function, it has it's own environment. If you want the dataframes to be created inside the function call (which is what I think you were doing before), you should

Re: [R] writing function

2010-05-24 Thread arnaud Gaboury
Thank you so much. You are totally right. -Original Message- From: Joshua Wiley [mailto:jwiley.ps...@gmail.com] Sent: Monday, May 24, 2010 6:33 PM To: arnaud Gaboury Cc: r-help@r-project.org Subject: Re: [R] writing function My guess is that either ls(), called inside grep

Re: [R] writing function

2010-05-24 Thread Joshua Wiley
-help@r-project.org Subject: Re: [R] writing function My guess is that either ls(), called inside grep() or mget() is looking in an environment you do not want it to.  When you create a function, it has it's own environment.  If you want the dataframes to be created inside the function call

[R] writing function

2010-05-20 Thread arnaud Gaboury
Dear group, I am trying to write functions, but as a beginner, everything is not so obvious. Let's say I want the results in a list of elemts like this : tot1, tot2, etc Here is a function: toto - function(x,y) { for(i in x:y){ paste(c(tot,i),collapse=)-(i*2) } } If I type this :

Re: [R] writing function

2010-05-20 Thread Tal Galili
Try this: paste(tot, 4:16, sep = ) Or: func - function(x,y) { paste(tot, x:y, sep = ) } func(4,16) Contact Details:--- Contact me: tal.gal...@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) |

Re: [R] writing function

2010-05-20 Thread Ivan Calandra
Hi, the problem is not about the environment, but about the paste(c(tot, i), collapse = ) which is not recognized as an object. Maybe assign() could do the trick You could also do it this way (though it's not exactly what you want, but it might be better): toto - function(x,y){ tot -

Re: [R] writing function

2010-05-20 Thread Ivan Calandra
Hi Tal, You're probably right, but I think it's never a waste to get diverse solutions :) Cheers, Ivan Le 20 mai 2010 à 19:26, Tal Galili a écrit : Hi Ivan, I am not sure if the poster (arnaud) intended for a list() object (although that's what he wrote, I suspect he intended for a

Re: [R] writing function

2010-05-20 Thread Joshua Wiley
Hello, I am guessing by my environment you mean the global environment (where you normally assign things from the console). It also looks like you would like the results of your function call to be a set of new objects created. If that is what you are looking for, try: toto - function(x,y) {

Re: [R] writing function

2010-05-20 Thread Wu Gong
## Create a function to assign a series of values to a list of objects ## The assign function can only assign one value (could be a vector) to a name ## Set the environment to be global, otherwise the objects can't be used outside the function ## List objects that have been created toto -

[R] writing function ( 'plot' and 'if') problem

2010-04-13 Thread casperyc
=== 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

Re: [R] writing function ( 'plot' and 'if') problem

2010-04-13 Thread Peter Alspach
-help@r-project.org Subject: [R] 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

Re: [R] writing function ( 'plot' and 'if') problem

2010-04-13 Thread casperyc
what i am triyng to do is when ds=1 give me a list ds=2 plot Thanks casper -- View this message in context: http://n4.nabble.com/writing-function-plot-and-if-problem-tp1839091p1839125.html Sent from the R help mailing list archive at Nabble.com.

Re: [R] writing function ( 'plot' and 'if') problem

2010-04-13 Thread David Winsemius
On Apr 13, 2010, at 5:41 PM, casperyc wrote: === myf=function(ds=1){ x=rnorm(10) y=rnorm(10) { #start of if if (ds==1) { list(x,y) } else (ds==2) ?if That seems odd. I would expect this function to return TRUE or FAKSE rather than proceeding to a plot function.

Re: [R] writing function ( 'plot' and 'if') problem

2010-04-13 Thread David Winsemius
On Apr 13, 2010, at 5:41 PM, casperyc wrote: === 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,

Re: [R] writing function ( 'plot' and 'if') problem

2010-04-13 Thread RICHARD M. HEIBERGER
The spurious condition (ds==2) is actually interpreted as the action taken by the else statement. Then the braced plot statement is seen as the next statement after the conclusion of the if () {} else () statement. [[alternative HTML version deleted]]

Re: [R] writing function ( 'plot' and 'if') problem

2010-04-13 Thread David Winsemius
On Apr 13, 2010, at 10:58 PM, RICHARD M. HEIBERGER wrote: The spurious condition (ds==2) is actually interpreted as the action taken by the else statement. Then the braced plot statement is seen as the next statement after the conclusion of the if () {} else () statement. I did

[R] writing function help

2010-04-10 Thread casperyc
Hi, I have written a function, ( or 2 functions) becasue there are only tiny difference, One of them has lines == #c2 (price.mat) call option price c2=c( max(S.mat[1,3]-K,0), max(S.mat[2,3]-K,0), max(S.mat[3,3]-K,0) ) (some lines) list( Stock Value=round(S.mat,dp),

[R] writing function (plot problem)

2010-04-10 Thread casperyc
Hi, === x=rnorm(20) y=rnorm(20) t=lm(y~x) plot(t) === you will get click or hit enter to next page... how do I write a function to archieve this ? say plot(x,y) then pause, wait plot(y,x) Thanks! casper -- View this message in context:

Re: [R] writing function (plot problem)

2010-04-10 Thread jim holtman
?devAskNewPage On Sat, Apr 10, 2010 at 7:49 PM, casperyc caspe...@hotmail.co.uk wrote: Hi, === x=rnorm(20) y=rnorm(20) t=lm(y~x) plot(t) === you will get click or hit enter to next page... how do I write a function to archieve this ? say