Skip to content
Back to formatted view

Raw Message

Message-ID: <1262978058766-1009932.post@n4.nabble.com>
Date: 2010-01-08T19:14:18Z
From: Lisa
Subject: Arguments of a function
In-Reply-To: <da79af331001081108v73b4b22cq7f26ccfd68f5a6ab@mail.gmail.com>

That's what I want. Thank you so much. 
Lisa


Henrique Dallazuanna wrote:
> 
> Try this:
> 
> my.f <- function(a, b) {
> 	x1 <- 2 * 3
>       x2 <- 3 / 6
>       x3 <- 4 * 4 / 5 - sqrt(2)
> 	y <- get(deparse(substitute(a))) + get(deparse(substitute(b)))
> 	return(y)
> }
> 
> my.f(x1, x2)
> 
> On Fri, Jan 8, 2010 at 4:15 PM, Lisa <lisajca at gmail.com> wrote:
>>
>> Dear all,
>>
>> I have a question about how to set arguments in my own function. For
>> example, I have a function that looks like this:
>>
>> my.f <- function(a = x1, b = x2)
>> {
>> ? x1 = equation 1
>> ? x2 = equation 2
>> ? x3 = equation 3
>> ? y = a + b
>> }
>>
>> x1, x2, and x3 are temporary variables (intermediate results) calculated
>> from other variables within the funciton. I want to use two of these
>> three
>> variables to calculate y, and write R script as below:
>>
>> my.f(a = x1, b = x2)
>>
>> or
>>
>> my.f(a = x2, b = x3)
>>
>> The error information shows that: ?objects 'x1', 'x2', or 'x3' not
>> found?.
>>
>> Can anybody help me solve this problem? Thanks in advance.
>>
>> Lisa
>>
>> --
>> View this message in context:
>> http://n4.nabble.com/Arguments-of-a-function-tp1009883p1009883.html
>> Sent from the R help mailing list archive at Nabble.com.
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
> 
> 
> 
> -- 
> Henrique Dallazuanna
> Curitiba-Paran?-Brasil
> 25? 25' 40" S 49? 16' 22" O
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: http://n4.nabble.com/Arguments-of-a-function-tp1009883p1009932.html
Sent from the R help mailing list archive at Nabble.com.