Re: [R] Sweave
Thanks Karen and Abhijit. I have read the section 4.1.2 of the Sweave user manual. Actually the manual lacks example code. I would like to change the option in includegraphics, not to change the true sizes of the pictures. This is what I usually do : \begin{figure} \centering echo=false,fig=true= print( acfplot( x ) ) @ \end{figure} Should I write : \begin{figure} \setkeys{Gin}{width=0.7\textwidth} \centering echo=false,fig=true= print( acfplot( x ) ) @ \end{figure} ? Thanks for your help, Randall 2010/8/18 Karen Kotschy ka...@sevenc.co.za Dear Randall I do it like this: \begin{center} \setkeys{Gin}{width=0.7\textwidth} \begin{Scode}{fig=T, echo=F} ... \end{Scode} \end{center} Hope this helps. Karen On Wed 18Aug10, Randall Wrong wrote: Dear R users, I am using Sweave. I would like to use the width option for the graphics : \begin{figure}[h!] \centering \includegraphics[width=0.7\textwidth]{x} \end{figure} How do I get this ? Thank you very much, Randall [[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.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. [[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] Sweave
I am sorry, I don't get it :-( What's the main body of the Sweave file ? Randall 2010/8/18 Abhijit Dasgupta adasgu...@araastat.com No, the \setkeys statement should be in the main body of the Sweave file, not in the R code part. On Aug 18, 2010 9:20 AM, Randall Wrong randall.wr...@gmail.com wrote: Thanks Karen and Abhijit. I have read the section 4.1.2 of the Sweave user manual. Actually the manual lacks example code. I would like to change the option in includegraphics, not to change the true sizes of the pictures. This is what I usually do : \begin{figure} \centering echo=false,fig=true= print( acfplot( x ) ) @ \end{figure} Should I write : \begin{figure} \setkeys{Gin}{width=0.7\textwidth} \centering echo=false,fig=true= print( acfplot( x ) ) @ \end{figure} ? Thanks for your help, Randall 2010/8/18 Karen Kotschy ka...@sevenc.co.za Dear Randall I do it like this: \begin{center} \setkeys{Gin}{width=0.7\textwidth} \begin{Scode}{fig=T, echo=F} ... \end{Scode} \end{center} Hope this helps. Karen On Wed 18Aug10, Randall Wrong wrote: Dear R users, I am using Sweave. I woul... http://www.R-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html http://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. [[alternative HTML version deleted]] __ r-h...@r-... [[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.
[R] Sweave
Dear R users, I am using Sweave. I would like to use the width option for the graphics : \begin{figure}[h!] \centering \includegraphics[width=0.7\textwidth]{x} \end{figure} How do I get this ? Thank you very much, Randall [[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] coda sweave
Thank you Bryan 2010/4/27 Brian Diggs dig...@ohsu.edu On 4/27/2010 1:42 PM, Randall Wrong wrote: Thank you so much Ista. I have problems with pictures too. \begin{figure} \centering fig=true= xyplot( mcmc(x) ) @ \end{figure} Why doesn't this work ? Sorry for posting all these questions :-( Best, Randall Check out FAQ 7.22. You need to use print(xyplot(mcmc(x))) since inside an Sweave evaluation, you are not at the command line and it does not print by default. 2010/4/27 Ista Zahnistaz...@gmail.com Hi Randall, Sounds like you need to make friends with the str() function, and perhaps read the documentation about data types in R. For your particular problem: library(coda) m1- matrix(runif(100), nrow=10) m1.sum- summary(mcmc(m1)) str(m1.sum) library(xtable) xtable(m1.sum$statistics) xtable(m1.sum$quantiles) Best, Ista On Tue, Apr 27, 2010 at 12:22 PM, Randall Wrongrandall.wr...@gmail.com wrote: This is the kind of output I get with summary(mcmc(x)). I would like it in LaTeX. There are two tables. Iterations = 1:10 Thinning interval = 1 Number of chains = 1 Sample size per chain = 10 1. Empirical mean and standard deviation for each variable, plus standard error of the mean: MeanSD Naive SE Time-series SE [1,] 0.7237 3.3741.067 1.252 [2,] -1.7883 4.3171.365 1.644 [3,] 0.8384 3.4221.082 1.047 [4,] 1.0750 3.1951.010 1.087 2. Quantiles for each variable: 2.5% 25% 50% 75% 97.5% var1 -1.5408 -0.91681 -0.1798 0.7134 7.929 var2 -4.1454 -3.89975 -3.5207 -2.1781 7.706 var3 -2.0412 -0.79606 0.3247 1.0445 7.999 var4 -0.9809 -0.08847 0.1895 0.4980 8.015 Thank you very much for any help, Randall 2010/4/27 Randall Wrongrandall.wr...@gmail.com I forgot to say that the coda package is loaded. Randall 2010/4/27 Randall Wrongrandall.wr...@gmail.com Dear R users, I have a matrix x of simulated values. Each column corresponds to one variable. summary(mcmc(x)) works fine I would like however to transform the ouput into a nice LaTeX code. xtable( summary(mcmc(x)) ) does not work. Thanks Randall [[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.htmlhttp://www.r-project.org/posting-guide.html http://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org [[alternative HTML version deleted]] -- Brian Diggs Senior Research Associate, Department of Surgery, Oregon Health Science University [[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.
[R] coda sweave
Dear R users, I have a matrix x of simulated values. Each column corresponds to one variable. summary(mcmc(x)) works fine I would like however to transform the ouput into a nice LaTeX code. xtable( summary(mcmc(x)) ) does not work. Thanks Randall [[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] coda sweave
I forgot to say that the coda package is loaded. Randall 2010/4/27 Randall Wrong randall.wr...@gmail.com Dear R users, I have a matrix x of simulated values. Each column corresponds to one variable. summary(mcmc(x)) works fine I would like however to transform the ouput into a nice LaTeX code. xtable( summary(mcmc(x)) ) does not work. Thanks Randall [[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] coda sweave
This is the kind of output I get with summary(mcmc(x)). I would like it in LaTeX. There are two tables. Iterations = 1:10 Thinning interval = 1 Number of chains = 1 Sample size per chain = 10 1. Empirical mean and standard deviation for each variable, plus standard error of the mean: MeanSD Naive SE Time-series SE [1,] 0.7237 3.3741.067 1.252 [2,] -1.7883 4.3171.365 1.644 [3,] 0.8384 3.4221.082 1.047 [4,] 1.0750 3.1951.010 1.087 2. Quantiles for each variable: 2.5% 25% 50% 75% 97.5% var1 -1.5408 -0.91681 -0.1798 0.7134 7.929 var2 -4.1454 -3.89975 -3.5207 -2.1781 7.706 var3 -2.0412 -0.79606 0.3247 1.0445 7.999 var4 -0.9809 -0.08847 0.1895 0.4980 8.015 Thank you very much for any help, Randall 2010/4/27 Randall Wrong randall.wr...@gmail.com I forgot to say that the coda package is loaded. Randall 2010/4/27 Randall Wrong randall.wr...@gmail.com Dear R users, I have a matrix x of simulated values. Each column corresponds to one variable. summary(mcmc(x)) works fine I would like however to transform the ouput into a nice LaTeX code. xtable( summary(mcmc(x)) ) does not work. Thanks Randall [[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] coda sweave
Thank you so much Ista. I have problems with pictures too. \begin{figure} \centering fig=true= xyplot( mcmc(x) ) @ \end{figure} Why doesn't this work ? Sorry for posting all these questions :-( Best, Randall 2010/4/27 Ista Zahn istaz...@gmail.com Hi Randall, Sounds like you need to make friends with the str() function, and perhaps read the documentation about data types in R. For your particular problem: library(coda) m1 - matrix(runif(100), nrow=10) m1.sum - summary(mcmc(m1)) str(m1.sum) library(xtable) xtable(m1.sum$statistics) xtable(m1.sum$quantiles) Best, Ista On Tue, Apr 27, 2010 at 12:22 PM, Randall Wrong randall.wr...@gmail.com wrote: This is the kind of output I get with summary(mcmc(x)). I would like it in LaTeX. There are two tables. Iterations = 1:10 Thinning interval = 1 Number of chains = 1 Sample size per chain = 10 1. Empirical mean and standard deviation for each variable, plus standard error of the mean: MeanSD Naive SE Time-series SE [1,] 0.7237 3.3741.067 1.252 [2,] -1.7883 4.3171.365 1.644 [3,] 0.8384 3.4221.082 1.047 [4,] 1.0750 3.1951.010 1.087 2. Quantiles for each variable: 2.5% 25% 50% 75% 97.5% var1 -1.5408 -0.91681 -0.1798 0.7134 7.929 var2 -4.1454 -3.89975 -3.5207 -2.1781 7.706 var3 -2.0412 -0.79606 0.3247 1.0445 7.999 var4 -0.9809 -0.08847 0.1895 0.4980 8.015 Thank you very much for any help, Randall 2010/4/27 Randall Wrong randall.wr...@gmail.com I forgot to say that the coda package is loaded. Randall 2010/4/27 Randall Wrong randall.wr...@gmail.com Dear R users, I have a matrix x of simulated values. Each column corresponds to one variable. summary(mcmc(x)) works fine I would like however to transform the ouput into a nice LaTeX code. xtable( summary(mcmc(x)) ) does not work. Thanks Randall [[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.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org [[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.
[R] lapply - function with arguments
Dear R users, I have created a function f of n, a and b : f(n,a,b) I would like to apply this function several times to some values of n. a and b are held constant. I was thinking of using lapply. How can I do this ? Thank you very much Randall [[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] lapply - function with arguments
Thank you Jim 2010/4/13 jim holtman jholt...@gmail.com lapply(yourList, f, a=1, b=2) On Tue, Apr 13, 2010 at 9:11 AM, Randall Wrong randall.wr...@gmail.comwrote: Dear R users, I have created a function f of n, a and b : f(n,a,b) I would like to apply this function several times to some values of n. a and b are held constant. I was thinking of using lapply. How can I do this ? Thank you very much Randall [[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.htmlhttp://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]] __ 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] Gamma parametrization
Thank you very much Jay. 2010/3/19 G. Jay Kerns gke...@ysu.edu Dear Randall, On Fri, Mar 19, 2010 at 10:24 AM, Randall Wrong randall.wr...@gmail.com wrote: Dear R users, ?rgamma gives me : rgamma(n, shape, rate = 1, scale = 1/rate) rate: an alternative way to specify the scale. The Gamma distribution with parameters shape = a and scale = s has density f(x)= 1/(s^a Gamma(a)) x^(a-1) e^-(x/s) Should I understand that scale=1/rate ? Is it written somewhere ? You are kidding, right? It is written 8 lines above your question, by my count. :-) Perhaps you meant rate = 1/scale. Then rgamma(n, shape=a, scale = s) should be equivalent to rgamma(n, shape=a, rate =1/s). Yep: dgamma(2, shape = 3, scale = 4) dgamma(2, shape = 3, rate = 1/4) I don't find this very clear. Thanks for your help. Randall The point is that some books (and software) parameterize by the 'scale', and a whole other bunch parameterize by the 'rate'. The reader (and user) always needs to be careful that the version used is the one expected. And the help file says that S doesn't have a 'scale' parameter at all. Just be careful, and you should be fine. And IMHO, given that the PDF of the density is shown it is reasonably clear as-is. Best, Jay *** G. Jay Kerns, Ph.D. Associate Professor Department of Mathematics Statistics Youngstown State University Youngstown, OH 44555-0002 USA Office: 1035 Cushwa Hall Phone: (330) 941-3310 Office (voice mail) -3302 Department -3170 FAX VoIP: gjke...@ekiga.net E-mail: gke...@ysu.edu http://people.ysu.edu/~gkerns/ [[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.
[R] Gamma parametrization
Dear R users, ?rgamma gives me : rgamma(n, shape, rate = 1, scale = 1/rate) rate: an alternative way to specify the scale. The Gamma distribution with parameters shape = a and scale = s has density f(x)= 1/(s^a Gamma(a)) x^(a-1) e^-(x/s) Should I understand that scale=1/rate ? Is it written somewhere ? Then rgamma(n, shape=a, scale = s) should be equivalent to rgamma(n, shape=a, rate =1/s). I don't find this very clear. Thanks for your help. Randall [[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] counting the number of ones in a vector
Thank you Gavin and Bert 2010/3/4 Gavin Simpson gavin.simp...@ucl.ac.uk On Thu, 2010-03-04 at 00:03 +0100, Randall Wrong wrote: Thanks to all of you ! (Benjamin Nutter, Henrique Dallazuanna, Tobias Verbeke, Jorge Ivan Velez, David Reinke and Gavin Simpson) x - c(1, 1, 1, NA, NA, 2, 1, NA) table(x)[1] 1 4 Why do I get two numbers ? It is a printing a named vector. The 1 is the group of factor level, the 4 is the count, try: unname(table(x)[1]) and str(table(x)[1]) etc to see what is going on. HTH G Thanks, Randall 2010/2/26 Nutter, Benjamin nutt...@ccf.org But if x has any missing values: x - c(1, 1, 1, NA, NA, 2, 1, NA) sum( x == 1) [1] NA sum(x==1, na.rm=TRUE) [1] 4 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Henrique Dallazuanna Sent: Friday, February 26, 2010 9:47 AM To: Randall Wrong Cc: r-help@r-project.org Subject: Re: [R] counting the number of ones in a vector Try: sum(x == 1) On Fri, Feb 26, 2010 at 11:40 AM, Randall Wrong randall.wr...@gmail.com wrote: Dear R users, I want to count the number of ones in a vector x. That's what I did : length( x[x==1] ) Is that a good solution ? Thank you very much, Randall [[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.htmlhttp://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@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.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. === P Please consider the environment before printing this e-mail Cleveland Clinic is ranked one of the top hospitals in America by U.S.News World Report (2009). Visit us online at http://www.clevelandclinic.org for a complete listing of our services, staff and locations. Confidentiality Note: This message is intended for use only by the individual or entity to which it is addressed and may contain information that is privileged, confidential, and exempt from disclosure under applicable law. If the reader of this message is not the intended recipient or the employee or agent responsible for delivering the message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please contact the sender immediately and destroy the material in its entirety, whether electronic or hard copy. Thank you. -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.ukhttp://gavin.simpsonatnospamucl.ac.uk/ Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% [[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] counting the number of ones in a vector
Thanks to all of you ! (Benjamin Nutter, Henrique Dallazuanna, Tobias Verbeke, Jorge Ivan Velez, David Reinke and Gavin Simpson) x - c(1, 1, 1, NA, NA, 2, 1, NA) table(x)[1] 1 4 Why do I get two numbers ? Thanks, Randall 2010/2/26 Nutter, Benjamin nutt...@ccf.org But if x has any missing values: x - c(1, 1, 1, NA, NA, 2, 1, NA) sum( x == 1) [1] NA sum(x==1, na.rm=TRUE) [1] 4 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Henrique Dallazuanna Sent: Friday, February 26, 2010 9:47 AM To: Randall Wrong Cc: r-help@r-project.org Subject: Re: [R] counting the number of ones in a vector Try: sum(x == 1) On Fri, Feb 26, 2010 at 11:40 AM, Randall Wrong randall.wr...@gmail.com wrote: Dear R users, I want to count the number of ones in a vector x. That's what I did : length( x[x==1] ) Is that a good solution ? Thank you very much, Randall [[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.htmlhttp://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@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.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. === P Please consider the environment before printing this e-mail Cleveland Clinic is ranked one of the top hospitals in America by U.S.News World Report (2009). Visit us online at http://www.clevelandclinic.org for a complete listing of our services, staff and locations. Confidentiality Note: This message is intended for use only by the individual or entity to which it is addressed and may contain information that is privileged, confidential, and exempt from disclosure under applicable law. If the reader of this message is not the intended recipient or the employee or agent responsible for delivering the message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please contact the sender immediately and destroy the material in its entirety, whether electronic or hard copy. Thank you. [[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] t-distribution values
Hi ! I would try pt for the probability distribution function. ?pt pt(q=-2, df=5) 2010/2/26 áÎÔÏÎ íÏÒËÏ×ÉÎ a-morko...@yandex.ru Dear all, how to calculate values of t-distribution for given values of d.f. using R functions? Anton __ 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.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[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.
[R] counting the number of ones in a vector
Dear R users, I want to count the number of ones in a vector x. That's what I did : length( x[x==1] ) Is that a good solution ? Thank you very much, Randall [[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.
[R] counting the number of ones in a vector
Dear R users, I want to count the number of ones in a vector x. That's what I did : length( x[x==1] ) Is that a good solution ? Thank you very much, Randall [[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] multi-argument returns
Thanks to Patrick Burns, Bert Gunter, Steve Lianoglou, and Professor Brian Ripley. 2010/2/17 Prof Brian Ripley rip...@stats.ox.ac.uk On Wed, 17 Feb 2010, Randall Wrong wrote: Dear R users, I have multi-argument returns in a function and I am warned by the program they are deprecated. Defunct as from the next R release. I have found this in the R-help archives : in 2001! http://tolstoy.newcastle.edu.au/R/help/01c/0319.html http://tolstoy.newcastle.edu.au/R/help/01c/0356.html Since I am not too good at programming, the list solution seems the better one for me. It is also the one advocated by Kevin Murphy. So rather than writing return(x,y,z), I should write at the end of my function : return(list(x=x,y=y,z=z)) is the preferred replacement. (As the help page for return() has long said.) g=function() { #... result=list(x,y,z) return(result) } Is that correct ? Then shoud l use g[1] or g[[1]] ? No change is needed (I think you mean g()$x etc) as return(x,y,z) and return(list(x=x,y=y,z=z)) are identical in their effects. Thank you for you help. Randall -- Brian D. Ripley, rip...@stats.ox.ac.uk 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 [[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.
[R] multi-argument returns
Dear R users, I have multi-argument returns in a function and I am warned by the program they are deprecated. I have found this in the R-help archives : http://tolstoy.newcastle.edu.au/R/help/01c/0319.html http://tolstoy.newcastle.edu.au/R/help/01c/0356.html Since I am not too good at programming, the list solution seems the better one for me. It is also the one advocated by Kevin Murphy. So rather than writing return(x,y,z), I should write at the end of my function : g=function() { #... result=list(x,y,z) return(result) } Is that correct ? Then shoud l use g[1] or g[[1]] ? Thank you for you help. Randall [[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.