Un texte encapsul? et encod? dans un jeu de caract?res inconnu a ?t? nettoy?... Nom : non disponible URL : <https://stat.ethz.ch/pipermail/r-help/attachments/20100416/3049d656/attachment.pl>
You can return a single object from a function. If you want multiple values, use a list: f <- function(x,y,z){ .... return(list(x=x, y=y, z=z)) } value <- f(x,y,z) # now copy the values x <- value$x y <- value$y z <- value$z On Fri, Apr 16, 2010 at 12:02 PM, Gustave Lefou <gustave5000@gmail.com>wrote:> Dear R users, > > I have a function which takes as arguments big arrays, say : w, x , y and > z. > > My function changes these arrays and I want them as result/output. > > I have tried to write return(w,x,y,z), and thus to replace the previous w, > x, y and z. It does not seem to work. > > What can I do ? > > Thank you very much, > Gustave > > [[alternative HTML version deleted]] > > ______________________________________________ > 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<http://www.r-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? [[alternative HTML version deleted]]
Below Bert Gunter Genentech Nonclinical Statistics -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Gustave Lefou Sent: Friday, April 16, 2010 9:03 AM To: r-help at r-project.org Subject: [R] return of a function Dear R users, I have a function which takes as arguments big arrays, say : w, x , y and z. My function changes these arrays and I want them as result/output. I have tried to write return(w,x,y,z), and thus to replace the previous w, x, y and z. It does not seem to work. What can I do ? -- 1. Read the Help file? -- which says: return(value) Arguments: value: An expression. -- and note that w,x,y,z is **not** a legal R expression 2. Have you read the online documentation, including an Introduction to R? There you would find many examples. 3. return(list(w,x,y,z)) ## is what you want ## or even list(w,x,y,z) ## without the return(), as the last R expression is by default what is returned. Thank you very much, Gustave [[alternative HTML version deleted]] ______________________________________________ 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.
On Apr 16, 2010, at 12:02 PM, Gustave Lefou wrote:> Dear R users, > > I have a function which takes as arguments big arrays, say : w, x , > y and z. > > My function changes these arrays and I want them as result/output. > > I have tried to write return(w,x,y,z), and thus to replace the > previous w, > x, y and z. It does not seem to work.Right. Two misconceptions here. First, return() accepts one object, which could be a list of items. Second, just because you return it with a name that is the same as some obkect outside the function does not mean that the new values will be placed in the "outside object". In fact if you do not assign the returned value to something, it will be temporarily placed in .LastValue and then overwritten when the next evaluation operation occurs. You need to assign the result of a function to some object.> > What can I do ?Read more about functions and do more examples with small objects to see the effects on test cases. -- David Winsemius, MD West Hartford, CT