Re: [R] return(x=x,y=y,prob=prob) hasn't been used in R now?
Hi! Use a list structure for all the components you want to have returned by the function: return(list(x=x, y=y, prob=prob)) Christian __ 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.
Re: [R] return(x=x,y=y,prob=prob) hasn't been used in R now?
It works well. Thanks a lot. On 9/23/07, Christian Ritz [EMAIL PROTECTED] wrote: Hi! Use a list structure for all the components you want to have returned by the function: return(list(x=x, y=y, prob=prob)) Christian -- With Kind Regards, oooO: (..): :\.(:::Oooo:: ::\_)::(..):: :::)./::: ::(_/ : [***] Zhi Jie,Zhang ,PHD Tel:86-21-54237149 Dept. of Epidemiology,School of Public Health,Fudan University Address:No. 138 Yi Xue Yuan Road,Shanghai,China Postcode:200032 Email:[EMAIL PROTECTED] Website: www.statABC.com [***] oooO: (..): :\.(:::Oooo:: ::\_)::(..):: :::)./::: ::(_/ : [[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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] return(x=x,y=y,prob=prob) hasn't been used in R now?
On Sun, 23 Sep 2007, Peter Dalgaard wrote: zhijie zhang wrote: Dear friends, Now, when i use the argument return(x=x,y=y,prob=prob) , R displays the waring message: Warning message: The return value for multiple variables wasn't used in: return(x = x, y = gy, prob = prob) I used the methods of help.search(return) and ?return to get some help, but didn't find info on it. Anybody knows how it should be used correctly? Return(value) takes only one argument. To return a list, return(list(x=x,y=y,prob=prob)) I bet the author of help(return) thought that this was implied clearly enough. and the warning message in English is not what is quoted here: f - function() return(x=pi, y=pi) f() $x [1] 3.141593 $y [1] 3.141593 Warning message: In return(x = pi, y = pi) : multi-argument returns are deprecated so they are in fact used. What is puzzling is that anyone is still trying to use them years after they were deprecated (and as the help page says they were never documented in S, quite how they ever got into circulation in R). #EXAMPLES a-function(x,y,z) { gx-seq(1,10,length.out=20) gy-gx prob-matrix(20,20) for (i in 1:20) { for (j in 1:20) { prob-0.1 } } return(x=gx,y=gy,prob=prob) } a(1,1,1) # the warning message will display Thanks. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ 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.
Re: [R] return(x=x,y=y,prob=prob) hasn't been used in R now?
Dear Prof. Brian Ripley, You are absolutely right. The warning message in R for my Chinese Windows system is Chinese words, so i translate it into english, which maybe not that exact in the meanings. Thanks very much. On 9/23/07, Prof Brian Ripley [EMAIL PROTECTED] wrote: On Sun, 23 Sep 2007, Peter Dalgaard wrote: zhijie zhang wrote: Dear friends, Now, when i use the argument return(x=x,y=y,prob=prob) , R displays the waring message: Warning message: The return value for multiple variables wasn't used in: return(x = x, y = gy, prob = prob) I used the methods of help.search(return) and ?return to get some help, but didn't find info on it. Anybody knows how it should be used correctly? Return(value) takes only one argument. To return a list, return(list(x=x,y=y,prob=prob)) I bet the author of help(return) thought that this was implied clearly enough. and the warning message in English is not what is quoted here: f - function() return(x=pi, y=pi) f() $x [1] 3.141593 $y [1] 3.141593 Warning message: In return(x = pi, y = pi) : multi-argument returns are deprecated so they are in fact used. What is puzzling is that anyone is still trying to use them years after they were deprecated (and as the help page says they were never documented in S, quite how they ever got into circulation in R). #EXAMPLES a-function(x,y,z) { gx-seq(1,10,length.out=20) gy-gx prob-matrix(20,20) for (i in 1:20) { for (j in 1:20) { prob-0.1 } } return(x=gx,y=gy,prob=prob) } a(1,1,1) # the warning message will display Thanks. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 -- With Kind Regards, oooO: (..): :\.(:::Oooo:: ::\_)::(..):: :::)./::: ::(_/ : [***] Zhi Jie,Zhang ,PHD Tel:86-21-54237149 Dept. of Epidemiology,School of Public Health,Fudan University Address:No. 138 Yi Xue Yuan Road,Shanghai,China Postcode:200032 Email:[EMAIL PROTECTED] Website: www.statABC.com [***] oooO: (..): :\.(:::Oooo:: ::\_)::(..):: :::)./::: ::(_/ : [[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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] return(x=x,y=y,prob=prob) hasn't been used in R now?
I don't know what exactly you want the program to do. But if you want to let the function to return several values in the same time, you have to put them into a list. E.g. in the following program, the function will return 4 different things, x and y are vectors, prob is a matrix and p is a scalor. Hope this helps, Honglian a-function(x,y) { gx-seq(1,x,length.out=y) gy-gx prob-matrix(gy,nrow=2) for (i in 1:y) { for (j in 1:y) p-0.1 } lst-list(x=gx,y=gy,prob=prob, p=p) return(lst) } b=a(10, 20) __ From: zhijie zhang [EMAIL PROTECTED] To: Prof Brian Ripley [EMAIL PROTECTED] CC: [EMAIL PROTECTED] Subject: Re: [R] return(x=x,y=y,prob=prob) hasn't been used in R now? Date: Sun, 23 Sep 2007 22:03:22 +0800 Dear Prof. Brian Ripley, You are absolutely right. The warning message in R for my Chinese Windows system is Chinese words, so i translate it into english, which maybe not that exact in the meanings. Thanks very much. On 9/23/07, Prof Brian Ripley [EMAIL PROTECTED] wrote: On Sun, 23 Sep 2007, Peter Dalgaard wrote: zhijie zhang wrote: Dear friends, Now, when i use the argument return(x=x,y=y,prob=prob) , R displays the waring message: Warning message: The return value for multiple variables wasn't used in: return(x = x, y = gy, prob = prob) I used the methods of help.search(return) and ?return to get some help, but didn't find info on it. Anybody knows how it should be used correctly? Return(value) takes only one argument. To return a list, return(list(x=x,y=y,prob=prob)) I bet the author of help(return) thought that this was implied clearly enough. and the warning message in English is not what is quoted here: f - function() return(x=pi, y=pi) f() $x [1] 3.141593 $y [1] 3.141593 Warning message: In return(x = pi, y = pi) : multi-argument returns are deprecated so they are in fact used. What is puzzling is that anyone is still trying to use them years after they were deprecated (and as the help page says they were never documented in S, quite how they ever got into circulation in R). #EXAMPLES a-function(x,y,z) { gx-seq(1,10,length.out=20) gy-gx prob-matrix(20,20) for (i in 1:20) { for (j in 1:20) { prob-0.1 } } return(x=gx,y=gy,prob=prob) } a(1,1,1) # the warning message will display Thanks. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 -- With Kind Regards, oooO: (..): :\.(:::Oooo:: ::\_)::(..):: :::)./::: ::(_/ : [***] Zhi Jie,Zhang ,PHD Tel:86-21-54237149 Dept. of Epidemiology,School of Public Health,Fudan University Address:No. 138 Yi Xue Yuan Road,Shanghai,China Postcode:200032 Email:[EMAIL PROTECTED] Website: www.statABC.com [***] oooO: (..): :\.(:::Oooo:: ::\_)::(..):: :::)./::: ::(_/ : [[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 and provide commented, minimal, self-contained, reproducible code. _ FREE pop-up blocking with the new MSN Toolbar [1]MSN Toolbar Get it now! References 1. http://g.msn.com/8HMBEN/2755??PS=47575 __ 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.