background preloader

R Programming

Facebook Twitter

Pbd: programming with big data in R. My R and Climate Change Learning Curve. Lexical scope and function closures in R. Introduction R is different to many “easy to use” statistical software packages – it expects to be given commands at the R command prompt.

Lexical scope and function closures in R

This can be intimidating for new users, but is at the heart of its power. Most powerful software tools have an underlying scripting language. This is because scriptable tools are typically more flexible, and easier to automate, script, program, etc. In fact, even software packages like Excel or Minitab have a macro programming language behind the scenes available for “power users” to exploit. Programming from the ground up It is natural to want to automate (repetitive) tasks on a computer, to automate a “work flow”. Next, one can add in simple control structures, to support looping, branching and conditional execution. Although scripting is a simple form of programming, it isn’t “real” programming, or software engineering.

Functions and procedures Variable scope. R - Books. Missing Data. In R, missing values are represented by the symbol NA (not available) .

Missing Data

Impossible values (e.g., dividing by zero) are represented by the symbol NaN (not a number). Unlike SAS, R uses the same symbol for character and numeric data. Testing for Missing Values # returns TRUE of x is missing y <- c(1,2,3,NA) # returns a vector (F F F T) Recoding Values to Missing # recode 99 to missing for variable v1 # select rows where v1 is 99 and recode column v1 mydata$v1[mydata$v1==99] <- NA. R Tutorials. Preamble There is plenty to say about data frames because they are the primary data structure in R.

R Tutorials

Some of what follows is essential knowledge. Some of it will be satisfactorily learned for now if you remember that "R can do that. " I will try to point out which parts are which. Set aside some time. Definition and Examples (essential) A data frame is a table, or two-dimensional array-like structure, in which each column contains measurements on one variable, and each row contains one case. Let's say we've collected data on one response variable or DV from 15 subjects, who were divided into three experimental groups called control ("contr"), treatment one ("treat1"), and treatment two ("treat2"). Contr treat1 treat2 --------------------------- 22 32 30 18 35 28 25 30 25 25 42 22 20 31 33 --------------------------- Omegahat Statistical Computing. R Time Series Tutorial. Probability Distributions. Say it in R with "by", "apply" and friends. R is a language, as Luis Apiolaza pointed out in his recent post.

Say it in R with "by", "apply" and friends

This is absolutely true, and learning a programming language is not much different from learning a foreign language. It takes time and a lot of practice to be proficient in it. I started using R when I moved to the UK and I wonder, if I have a better understanding of English or R by now. Languages are full of surprises, in particular for non-native speakers. The other day I learned that there is courtesy and curtsey. With languages you can get into habits of using certain words and phrases, but sometimes you see or hear something, which shakes you up again. Resources to help you learn and use R.

R. Look what I found: two amazing charts. While doing some research for my statistics blog, I came across a beauty by Lane Kenworthy from almost a year ago (link) via this post by John Schmitt (link).

Look what I found: two amazing charts

How embarrassing is the cost effectiveness of U.S. health care spending? When a chart is executed well, no further words are necessary. I'd only add that the other countries depicted are "wealthy nations". Even more impressive is this next chart, which plots the evolution of cost effectiveness over time. An important point to note is that the U.S. started out in 1970 similar to the other nations. Let's appreciate this beauty: Let the data speak for itself. Plyr. Knitr: Elegant, flexible and fast dynamic report generation with R. Overview The knitr package was designed to be a transparent engine for dynamic report generation with R, solve some long-standing problems in Sweave, and combine features in other add-on packages into one package (knitr ≈ Sweave + cacheSweave + pgfSweave + weaver + animation::saveLatex + R2HTML::RweaveHTML + highlight::HighlightWeaveLatex + 0.2 * brew + 0.1 * SweaveListingUtils + more).

knitr: Elegant, flexible and fast dynamic report generation with R

This package is developed on GitHub; for installation instructions and FAQ’s, see README. This website serves as the full documentation of knitr, and you can find the main manual, the graphics manual and other demos / examples here. For a more organized reference, see the knitr book. Motivation. Short-refcard.pdf (application/pdf Object) Useful Links. ComputingPresentation.R.conditionals.pdf (application/pdf Object)

Community sites

R tools. R tutoriels et des lésions.