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, that I wouldn't know where to begin. Ergo the tutorial suggestions. May I also suggest that should anyone else care to have a go at helping, that they reply privately, as this somehow does not seem the right venue for such basic tutorials. Cheers, Bert On Fri, Sep 7, 2012 at 11:00 AM, wwreith <reith_will...@bah.com> 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<-function(x) > { > x<-x+1 > } > ADD(z) > z > output for z is 1 not the expected 2. > > Now if I were to do print(x+1) instead of x<-x+1 it does return 2, so the > function seems ok with x+1, but not ok with x<-. Is there a way to define a > variable inside a function or am I violating some rule that I don't know > about? > > Thanks for the help! > > Will > > > > > > -- > View this message in context: > http://r.789695.n4.nabble.com/Trying-to-learn-how-to-write-a-function-can-t-define-a-variable-tp4642528.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@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. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm ______________________________________________ R-help@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.