background preloader

R Programming - Manuals

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

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

An Introduction to R Table of Contents This is an introduction to R (“GNU S”), a language and environment for statistical computing and graphics. R is similar to the award-winning1 S system, which was developed at Bell Laboratories by John Chambers et al. It provides a wide variety of statistical and graphical techniques (linear and nonlinear modelling, statistical tests, time series analysis, classification, clustering, ...). This manual provides information on data types, programming elements, statistical modelling and graphics. This manual is for R, version 3.1.0 (2014-04-10). Copyright © 1990 W. Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies. Preface This introduction to R is derived from an original set of notes describing the S and S-PLUS environments written in 1990–2 by Bill Venables and David M. Comments and corrections are always welcome. Suggestions to the reader 1.1 The R environment Try ?

Subsetting · Advanced R. R’s subsetting operators are powerful and fast. Mastery of subsetting allows you to succinctly express complex operations in a way that few other languages can match. Subsetting is hard to learn because you need to master a number of interrelated concepts: The three subsetting operators.The six types of subsetting.Important differences in behaviour for different objects (e.g., vectors, lists, factors, matrices, and data frames).The use of subsetting in conjunction with assignment. This chapter helps you master subsetting by starting with the simplest type of subsetting: subsetting an atomic vector with [. It then gradually extends your knowledge, first to more complicated data types (like arrays and lists), and then to the other subsetting operators, [[ and $. Subsetting is a natural complement to str(). str() shows you the structure of any object, and subsetting allows you to pull out the pieces that you’re interested in. Quiz Outline Data types starts by teaching you about [. Data types !

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. 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 Bloggers ( is a website that aggregates over 50 different blogs that focus on R. R Beginner's Guide 11/1/2010 Update: Statistical Analysis with R is now available! Lastly, I want to let you know that I am working on a beginner's guide for R.

Rtips. Revival 2014! Paul E. Johnson <pauljohn @ ku.edu> The original Rtips started in 1999. It became difficult to update because of limitations in the software with which it was created. Now I know more about R, and have decided to wade in again. In January, 2012, I took the FaqManager HTML output and converted it to LaTeX with the excellent open source program pandoc, and from there I’ve been editing and updating it in LyX. You are reading the New Thing! The first chore is to cut out the old useless stuff that was no good to start with, correct mistakes in translation (the quotation mark translations are particularly dangerous, but also there is trouble with ~, $, and -. (I thought it was cute to call this “StatsRus” but the Toystore’s lawyer called and, well, you know…) If you need a tip sheet for R, here it is. This is not a substitute for R documentation, just a list of things I had trouble remembering when switching from SAS to R. Heed the words of Brian D. 1.1 Bring raw numbers into R (05/22/2012) Step 1.

Cookbook for R » Cookbook for R Plot maps like a boss A new package OpenStreetMap has been released to CRAN this week which is designed to allow you to easily add satellite imagery, or open street maps to your plots. Raster maps are a great way to add context to your spatial data with a minimum outlay of effort. The syntax in OpenStreetMap is fairly simple, just give it a bounding box in lat/long and it will download a high quality raster image ready for plotting library(OpenStreetMap) library(rgdal) map <- openmap(c(70,-179), c(-70,179)) plot(map) (click for higher quality image) The above code downloads multiple map tiles and stitches together, with the level of zoom determined automatically. We can also access satellite imagery though Bing. map <- openmap(c(70,-179), c(-70,179),type='bing') plot(map) Now, that is all fine and dandy, but kind of useless unless you are able to combine it with your own data. In terms of combining maps with your data there are two options. We may also want to go the other way and transform the image.

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. In addition, a short guide to data analysis in a research methods course offers some more detail on graphing.) 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. Back to Top Installing R on your computer entering ?

R tells you where weapons go As an ameturer programmer (one without proper trainings in any mainstream programming language — C and Java) , the more I use R the more I understand the saying — “You are only bounded by your imagination”. The other day I suddenly recalled that someone did a very impressive Facebook map. I then thought it would be nice if I can put these “flows” on the map (or of the same sort) created in my first post. So, I googled around and found this brilliant blog that teaches you how to make flows (Great circles) step by step. Again, thanks to R, its great community and its openness, I created the following map of international weapon export in 2010 (from top 7 exporters). R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

Statistical Computing with R: A tutorial 0.1. What is R?R is a software package especially suitable for data analysis and graphical representation. Functions and results of analysis are all stored as objects, allowing easy function modification and model building. R provides the language, tool, and environment in one convenient package. It is very flexible and highly customizable. On the other hand, R has a few weaknesses. 0.2 Where do I get R? and follow the download instructions. 0.3 Invoking RIf properly installed, usually R has a shortcut icon on the desktop screen and/or you can find it under Start|Programs|R menu. To quit R, type q() at the R prompt (>) and press Enter key. Commands you entered can be easily recalled and modified. Interactive graphics can serve as a great learning tool. Effect of kernel choice, sample size and bandwidth can be conveniently illustrated by the following demonstration: 2.1 ComputationFirst of all, R can be used as an ordinary calculator.

Mapping the World’s Biggest Airlines The map above shows the routes flown by the top 7 airlines (by international passenger distance flown). The base map shows large urban areas and I have attempted to make it look a bit like the beautiful “Earth at Night” composite image produced by NASA. You can clearly see a relationship between where people live and where the big carriers fly to across Europe and the US but India and much of China have relatively few routes. I expect much of the slack is picked up by smaller airlines in these countries but they must represent key growth areas the world economy becomes increasingly driven by the east. This map isn’t meant to be comprehensive- I just wanted to make another example of a visualisation with ggplot2. How I did it Plotting great circles has become an increasingly popular thing to do with R (because they look cool) and the excellent flight path data freely available from the OpenFlights website provides a neat data source to play around with. Get a world map worldmap

Related: