Please forgive the relative lack of sophistication here -- I'm trying to learn R, remove the rust from my basic training in statistics, AND produce a useful result. I have two vectors of equal length, A and B, with a one-to-one correspondence between the elements (ie. A[i] corresponds to B[i]) which are provided by an SQL server upon which I can run any SQL statement. I would like to partition A (like breaks in a histogram) into some number of equal-size partitions, and then calculate and plot the mean value of the B's that correspond to the A's in each partition (or, more generally, produce some descriptive statistics for each set of B's, and potentially try to draw some inferences about the B's in each partition). I can imagine how to do this in Perl by writing a loop, but I suspect there may be a more natural way to do it in R, and would be grateful for any suggestions. Thanks. Regards, Mike ___________________________________________________ Michael Nielsen Synergy Plus Pty Ltd Sydney Level 5, 18-20 Orion Rd PO Box 4080, Lane Cove, NSW DC 2066 (Switch: ) +61 2 9425-3000 (Fax: ) +61 2 9418-9477 (Direct: ) +61 2 9425-3007 (Mobile: )0413-208-488 WebSite: www.synergy.com.au This email and any attachments are confidential. If you are not the intended recipient, please inform us as soon as possible and do not use, disclose, copy or distribute this information. -------------- next part -------------- An HTML attachment was scrubbed... URL: https://stat.ethz.ch/pipermail/r-help/attachments/20010418/9c91dd02/attachment.html
R Novice Question
2 messages · MichaelNielsen@synergy.com.au, Brian Ripley
On Wed, 18 Apr 2001 MichaelNielsen at synergy.com.au wrote:
Please forgive the relative lack of sophistication here -- I'm trying to learn R, remove the rust from my basic training in statistics, AND produce a useful result. I have two vectors of equal length, A and B, with a one-to-one correspondence between the elements (ie. A[i] corresponds to B[i]) which are provided by an SQL server upon which I can run any SQL statement. I would like to partition A (like breaks in a histogram) into some number of equal-size partitions, and then calculate and plot the mean value of the B's that correspond to the A's in each partition (or, more generally, produce some descriptive statistics for each set of B's, and potentially try to draw some inferences about the B's in each partition). I can imagine how to do this in Perl by writing a loop, but I suspect there may be a more natural way to do it in R, and would be grateful for any suggestions.
Use something like tapply(B, cut(A, 5), mean) cut() gives 5 (roughly) equal-sized pieces, and tapply partitions on the values of the cut and applies the function. For more complicated situations you might like to look at by().
Brian D. Ripley, ripley at 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 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._