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
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())])
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
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() or mget() is
>> looking in an environment you do not want it to. When you create a
>> function, it
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 ei
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 set
Dear group,
Here is my environment after I run a function, myfun()
>myfun()
> ls()
[1] "allcon""avprix16" "DailyPL100416" "DailyPL100419"
"DailyPL100420" "l" "ll""myl" "PL"
"PLdaily" "PLglobal" "PLmonthly"
[13] "Pos100415" "Pos100
## 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 <- functi
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) {
f
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
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
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) | www.b
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 :
>to
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 ta
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]]
_
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,
t
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.
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.
_
0 10:42 a.m.
> To: r-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)
> }
&g
===
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
?devAskNewPage
On Sat, Apr 10, 2010 at 7:49 PM, casperyc 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
>
> p
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:
http://n4
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),
"C
23 matches
Mail list logo