Dear Helplist Some time ago, Professor Ripley gave me a tip which I thought was very very useful for Monte Carlo simulation; I thought I'd pass it on to the list, and ask whether this or a similar example could be added to the sapply() manpage. Suppose I have ten N(0,1) random variables and I'm interested in the pair that are closest together: R> min(diff(sort(rnorm(10)))) [1] 0.04438955 To generate a PDF for this statistic one can use sapply() as follows: R> func <- function(n){min(diff(sort(rnorm(n))))} R> hist(sapply(rep(10,999),func),col="gray") This is *soooo* much better than having a loop! Cheers everyone! Anyone got any other interesting uses of sapply()? Would anyone on the List be interested in a collection specifically of neat R oneliners? -- Robin Hankin, Lecturer, School of Geographical and Environmental Science Private Bag 92019 Auckland New Zealand r.hankin at auckland.ac.nz tel 0064-9-373-7599 x6820; FAX 0064-9-373-7042 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Hi List,> Would anyone on > the List be interested in a collection specifically of neat R > oneliners?I am new to R and this would be neat idea to have a collection of code-snippets and how to solve "common" problems. It would be great! cheers steph -- Linux: the operating system with a CLUE... Command Line User Environment. -------------------------------------- Stephan Holl GnuPG Key-ID: 11946A09 ICQ# 117277975 -------------------------------------- -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Great idea ! I am sure it would be very useful - in particular to the newcomers to the R-land. The question is where to put it and how to organize it to make it useful ? Some database approach with web interface would be probably good in the long run. R Ryszard Czerminski phone: (781)994-0479 ArQule, Inc. email:ryszard at arqule.com 19 Presidential Way http://www.arqule.com Woburn, MA 01801 fax: (781)994-0679 -----Original Message----- From: Robin Hankin [mailto:r.hankin at auckland.ac.nz] Sent: Wednesday, June 26, 2002 12:52 AM To: r-help at stat.math.ethz.ch Subject: [R] sapply() and Monte Carlo Dear Helplist Some time ago, Professor Ripley gave me a tip which I thought was very very useful for Monte Carlo simulation; I thought I'd pass it on to the list, and ask whether this or a similar example could be added to the sapply() manpage. Suppose I have ten N(0,1) random variables and I'm interested in the pair that are closest together: R> min(diff(sort(rnorm(10)))) [1] 0.04438955 To generate a PDF for this statistic one can use sapply() as follows: R> func <- function(n){min(diff(sort(rnorm(n))))} R> hist(sapply(rep(10,999),func),col="gray") This is *soooo* much better than having a loop! Cheers everyone! Anyone got any other interesting uses of sapply()? Would anyone on the List be interested in a collection specifically of neat R oneliners? -- Robin Hankin, Lecturer, School of Geographical and Environmental Science Private Bag 92019 Auckland New Zealand r.hankin at auckland.ac.nz tel 0064-9-373-7599 x6820; FAX 0064-9-373-7042 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. -.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._. _._ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>>>>> "robin" == Robin Hankin <r.hankin at auckland.ac.nz> writes:robin> This is *soooo* much better than having a loop! Cheers everyone! robin> Anyone got any other interesting uses of sapply()? Would anyone on robin> the List be interested in a collection specifically of neat R robin> oneliners? When they are amusing, I forward them into a Wiki that I keep for brain dumping: http://software.biostat.washington.edu/wikis/front/NotesOnR I need to refactor this into appropriate sections (and occassional, add a small bit of markup, and occassionally remove them for better versions), but it's one place to add them. (there's a place to "add comments" at the bottom). I'm sure that there is a better place (perhaps someone could organize a Tips and Tricks FAQ?) best, -tony -- A.J. Rossini Rsrch. Asst. Prof. of Biostatistics U. of Washington Biostatistics rossini at u.washington.edu FHCRC/SCHARP/HIV Vaccine Trials Net rossini at scharp.org -------------- http://software.biostat.washington.edu/ ---------------- FHCRC: M: 206-667-7025 (fax=4812)|Voicemail is pretty sketchy/use Email UW: Th: 206-543-1044 (fax=3286)|Change last 4 digits of phone to FAX (my tuesday/wednesday/friday locations are completely unpredictable.) -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._