I am trying to understand how to write an "advanced" function. To do this, I am
examining the code of lm, a small part of the lm code is below. N
> lm
function (formula, data, subset, weights, na.action, method = "qr",
model = TRUE, x = FALSE, y = FALSE, qr = TRUE, singular.ok = TRUE,
c
altered.
Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
> Behalf
> Of David Winsemius
> Sent: Friday, September 07, 2012 1:35 PM
> To: wwreith
> Cc: r-help@r-
On Fri, Sep 7, 2012 at 3:16 PM, Rui Barradas wrote:
> Hello,
>
> Start by (re-)reading An Introduction to R, file R-intro.pdf in your doc
> directory. Chapter 10.
>
> You're just computing, not returning the result of that computation. Nor
> anything else, ADD() does not return a value.
Sure it d
On Sep 7, 2012, at 1:34 PM, David Winsemius wrote:
>
> On Sep 7, 2012, at 11:00 AM, wwreith wrote:
>
>> I am just starting to experiment with writing a function and have run into
>> what seems like a limitation or more likely a lack of understanding on my
>> part.
>>
>> Very Simple Example:
On Sep 7, 2012, at 11:00 AM, wwreith wrote:
> I am just starting to experiment with writing a function and have run into
> what seems like a limitation or more likely a lack of understanding on my
> part.
>
> Very Simple Example: I want to define a function that does 1+1=2.
>
> z<-1
> ADD<-fu
Hello,
Start by (re-)reading An Introduction to R, file R-intro.pdf in your doc
directory. Chapter 10.
You're just computing, not returning the result of that computation. Nor
anything else, ADD() does not return a value. (See the example in
R-intro, section 10.1)
And you need to assign the
WHEW! Have you read An Introduction to R? If not, stop and do so. If
you have, stop and do so again. Or look for other web tutorials (you
may get some suggestions here) or books (CRAN is a good place to look
for this).
The problem is that you are so far from understanding how a function
works, tha
On 07-09-2012, at 21:54, William Dunlap wrote:
> The functions
> f1 <- function(x) x <- x + 1
> and
> f2 <- function(x) x + 1
> both return the same value. You can see
> this by doing
> z1 <- f1(10) ; print(z1)
> z2 <- f2(10) ; print(z2)
> or just
> print(f1(10))
> print(f2(10))
>
>
gt; To: William Dunlap
> Cc: wwreith; r-help@r-project.org
> Subject: Re: [R] Trying to learn how to write a function... can't define a
> variable??
>
>
> On 07-09-2012, at 21:32, William Dunlap wrote:
>
> > Berend,
> > The OP's ADD() is returning the new v
On 07-09-2012, at 21:32, William Dunlap wrote:
> Berend,
> The OP's ADD() is returning the new value of x, as do all
> of your alternatives. His problem is that he is not assigning
> the output of ADD to a variable, as in
> z <- ADD(z)
> Ordinary functions do not alter their arguments. The
-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
> Behalf
> Of Berend Hasselman
> Sent: Friday, September 07, 2012 12:18 PM
> To: wwreith
> Cc: r-help@r-project.org
> Subject: Re: [R] Trying to learn how to write a function... can't define
On 07-09-2012, at 20:00, wwreith wrote:
> I am just starting to experiment with writing a function and have run into
> what seems like a limitation or more likely a lack of understanding on my
> part.
>
> Very Simple Example: I want to define a function that does 1+1=2.
>
> z<-1
> ADD<-functi
I am just starting to experiment with writing a function and have run into
what seems like a limitation or more likely a lack of understanding on my
part.
Very Simple Example: I want to define a function that does 1+1=2.
z<-1
ADD<-function(x)
{
x<-x+1
}
ADD(z)
z
output for z is 1 not the expec
13 matches
Mail list logo