The R programming language for programmers coming from other programming languages IntroductionAssignment and underscoreVariable name gotchasVectorsSequencesTypesBoolean operatorsListsMatricesMissing values and NaNsCommentsFunctionsScopeMisc.Other resources Ukrainian translation Other languages: Powered by Translate Introduction I have written software professionally in perhaps a dozen programming languages, and the hardest language for me to learn has been R. R is more than a programming language. This document is a work in progress. Assignment and underscore The assignment operator in R is <- as in e <- m*c^2. It is also possible, though uncommon, to reverse the arrow and put the receiving variable on the right, as in m*c^2 -> e. It is sometimes possible to use = for assignment, though I don't understand when this is and is not allowed. However, when supplying default function arguments or calling functions with named arguments, you must use the = operator and cannot use the arrow. At some time in the past R, or its ancestor S, used underscore as assignment. Vectors Sequences
R graphics plot gallery - plots, charts and graphs with R code R has great graphics and plotting capabilities and can produce a wide range of plots very easily. The following is an R plot gallery with a selection of different R plot types and graphs that were all generated with R. In each case you can click on the graph to see the commented code that produced the plot in R. This shows the spatial distribution of galaxies in the cluster Abell 85, using data from the NASA Extragalactic Database (NED). To follow a step-by-step tutorial showing how to create a similar plot in R, click here. There is now a Birmingham (UK) R user group: click here for more information An R chart of daily weather measurements taken at the University of Birmingham Wast Hill Observatory, using the excellent R lattice graphics package. Using ggplot2 to show mean temperature profiles and their error envelopes for cool-core and non-cool core clusters, from Sanderson et al. (2006). A plot of some blackbody curves for 3 different temperatures.
rgraphics R Graphicsby Paul Murrell The SECOND EDITION of this book is now available, with its own web page. A book on the core graphics facilities of the R language and environment for statistical computing and graphics (Chapman & Hall/CRC, August 2005). A link to the publisher's web page for the book. A list of Errata. PDF version of the preface, table of contents, and Chapters 1, 4, and 5. R code for figures: Chapter 1: An Introduction to R Graphics Chapter 2: Simple Usage of Traditional Graphics Chapter 3: Customising Traditional Graphics Chapter 4: Trellis Graphics: The Lattice Package Chapter 5: The Grid Graphics Model Chapter 6: The Grid Graphics Object Model Chapter 7: Developing New Graphics Functions and Objects Appendix A: A Brief Introduction to R Appendix B: Combining Traditional Graphics and Grid Graphics Extras: Some extra plots not in the book An R add-on package called "RGraphics" is available from CRAN. Figure 3.12 -- uses 'hjust' argument in grid.text()
Les templates en C++ Introduction Nous allons présenter la notion de template (patron en français). Les templates font parties des grands apports du C++ au langage C. Jusqu'ici on passait en paramètre des fonctions des variables. Avantages On appelle dans ce qui suit symbole indifféremment une fonction, une structure ou une classe. Inconvénients - Comme nous allons le voir par la suite, l'utilisation de template requiert quelques précautions d'usage (typename...) - Le programme est plus long à compiler. Quand utiliser des templates ? L'usage des templates est particulièrement pertinent pour définir des containers, c'est-à-dire des structures qui servent à stocker une collection d'objets (une liste, un vecteur, un graphe...). Les templates sont également adaptés pour définir des algorithmes génériques s'appliquant à une famille de classe. Que dois-je mettre dans les .hpp et dans les .cpp ? Le C++ étant un langage compilé, on ne peut évidemment pas imaginer de compiler pour un symbole donné toutes ses versions.
R Programming - Manuals R Basics The R & BioConductor manual provides a general introduction to the usage of the R environment and its basic command syntax. Code Editors for R Several excellent code editors are available that provide functionalities like R syntax highlighting, auto code indenting and utilities to send code/functions to the R console. Programming in R using Vim or Emacs Programming in R using RStudio Integrating R with Vim and Tmux Users interested in integrating R with vim and tmux may want to consult the Vim-R-Tmux configuration page. Finding Help Reference list on R programming (selection)R Programming for Bioinformatics, by Robert GentlemanAdvanced R, by Hadley WickhamS Programming, by W. Control Structures Conditional Executions Comparison Operators equal: ==not equal: ! Logical Operators If Statements If statements operate on length-one logical vectors. Syntax if(cond1=true) { cmd1 } else { cmd2 } Example if(1==0) { print(1) } else { print(2) } [1] 2 Avoid inserting newlines between '} else'. Loops Syntax
Announcing RPubs: A New Web Publishing Service for R « RStudio Blog Today we’re very excited to announce RPubs, a free service that makes it easy to publish documents to the web from R. RPubs is a quick and easy way to disseminate data analysis and R code and do ad-hoc collaboration with peers. RPubs documents are based on R Markdown, a new feature of knitr 0.5 and RStudio 0.96. RPubs documents include a moderated comment stream for feedback and dialog with readers, and can be updated with changes by publishing again from within RStudio. Note that you’ll only see the Publish button if you update to the latest version of RStudio (v0.96.230, available for download today). The markdown package RStudio has integrated support for working with R Markdown and publishing to RPubs, but we also want to make sure that no matter what tools you use it’s still possible to get the same results. The markdown package provides a standalone implementation of R Markdown rendering that can be integrated with other editors and IDEs. Gallery of examples Like this: Like Loading...
Percentile The nth percentile of an observation variable is the value that cuts off the first n percent of the data values when it is sorted in ascending order. Problem Find the 32nd, 57th and 98th percentiles of the eruption durations in the data set faithful. Solution We apply the quantile function to compute the percentiles of eruptions with the desired percentage ratios. > duration = faithful$eruptions # the eruption durations > quantile(duration, c(.32, .57, .98)) 32% 57% 98% 2.3952 4.1330 4.9330 Answer The 32nd, 57th and 98th percentiles of the eruption duration are 2.3952, 4.1330 and 4.9330 minutes respectively. Exercise Find the 17th, 43rd, 67th and 85th percentiles of the eruption waiting periods in faithful. Note There are several algorithms for the computation of percentiles.
Data Analysis in the Geosciences 22 January, 2013 Many things are easy in R are simple, but sometimes the solution is not obvious. Adding error bars to a bar plot is one of those things. The segments() command lets you draw line segments, provided you specify the coordinates of the beginning and end of the segments. You could use the locator() function to find the centers of the bars, but clicking on points can be imprecise. Here is how it all works. names <- c("squirrel", "rabbit", "chipmunk") means <- c(23, 28, 19) standardErrors <- c(1.2, 1.7, 0.9) Because the top of the plot is scaled to the tallest bar, the error bars will get clipped if I add them. plotTop <- max(means+standardErrors*2) First, I will plot the graph, with the bars filled with gray, with y-axis labels rotated (las=1), and with the limits on the y-axis expanded so they will include the error bars. barCenters <- barplot(means, names.arg=names, col="gray", las=1, ylim=c(0,plotTop)) Pretty straightforward!
R Beginner's Guide and R Bloggers Updates 1/1/2011 Update: Tal Galili wrote an article that revisits the first year of R-Bloggers and this post was listed as one of the top 14. Therefore, I decided to make a small update to each section. I start by describing the initial series of tutorials that I wrote. A few more have been added since and even more planned in the upcoming year. As always, an up to date listing of my articles can be found on the R Tutorial Series blog. New posts will also continue to be offered through the R Bloggers network. Since October 2009, I have written 13 articles [many more now, of course] for the R Tutorial Series blog. Introduction to R Descriptive Statistics Summary and Descriptive Statistics Data Visualization Scatterplots Correlation Zero-Order Correlations Regression I also have two additional R-related items to update you on. 1/1/2011 Update: I originally reported that 50 blogs composed the R Bloggers network. R Tutorial Series on R Bloggers R Beginner's Guide
Cookbook for R » Cookbook for R R for Psych Research This is one page of a series of tutorials for using R in psychological research. Much of material has also covered been covered in number of short courses or in a set of tutorials for specific problems. This particular page is an update of a previous guide to R which is being converted to HTML5 to be more readable. (For a very abbreviated form of this guide meant to help students do basic data analysis in a personality research course, see a very short guide. There are many possible statistical programs that can be used in psychological research. It has been claimed that "The statistical programming language and computing environment S has become the de-facto standard among statisticians. The R project, based upon the S and S+ stats packages, has developed an extremely powerful set of "packages" that operate within one program. Although many run R as a language and programming environment, there are Graphical User Interfaces (GUIs) available for PCs, Linux and Macs. Back to Top entering ?