advanced tips

How to use your favorite fonts in R charts

September 20, 2012 | David Smith

Today's guest post comes from Winston Chang, a software developer at RStudio — ed. When it comes to making figures in R, you can use any font you like, as long as it's Helvetica, Times, or Courier. Using other fonts that are installed on your computer can seem an impossible task, ... [Read more...]

How to create random binary matrices in R

September 4, 2012 | David Smith

It all started off as a simple question from Scott Chamberlain on Twitter: Make m x n matrix with randomly assigned 0/1 -__ apply(m, c(1,2), function(x) sample(c(0,1),1)) -- Better/faster solution? #rstats — Scott Chamberlain (@recology_) August 28, 2012 The goal was to create a matrix with randomly selected binary elements, ... [Read more...]

Puzzle: A path through pairs making squares

April 23, 2012 | David Smith

Ted Harding posed an interesting puzzle challenge on the r-help mailing list recently. Here's the puzzle: Take the numbers 1, 2, 3, etc. up to 17. Can you write out all seventeen numbers in a line so that every pair of numbers that are next to each other, adds up to give a square ... [Read more...]

Simplify working with times and dates in R

March 16, 2012 | David Smith

R has some very powerful built-in features for working with dates, times, and time-zones. But power and flexibility rarely correlate with ease-of-use, and this is no exception. The lubridate package comes to the rescue, make things a bit easier when working with chronological data in R. The paper Dates and ... [Read more...]

Optimization for Finance with R

January 9, 2012 | David Smith

Last year, the Statistics and Mathematics Department of the Vienna University School of Economics and Business presented a research seminar series on optimization, taught by R Core Group member Kurt Hornik (with Ronald Hochreiter and Stefan Theussl). Even if you couldn't make it to Austria to attend the course, the ... [Read more...]

Mixed-Effects Models in R with Quantum Forest

October 26, 2011 | David Smith

For anyone who wants to estimate linear or nonlinear mixed-effects models (aka random-effects models, hierarchical models or multilevel models) using the R language, the Quantum Forest blog has several recent posts that will be of interest. Written by Luis Apiolaza from the School of Forestry at the University of Canterbury ... [Read more...]

Using Google Spreadsheets with R: an update

September 15, 2011 | David Smith

Prompted by a rush of visitors from Andrew Gelman's blog, I went back and updated the details of my post from 2009 on reading data from Google Spreadsheets into R. Since then, Google had switched to using a secure (https) connection for Google Docs, which required some tweaks to the code. ... [Read more...]

9 more ways to bring data into R

August 26, 2011 | David Smith

Here's a followup to yesterday's post on using the rdatamarket package to import data into R. Ajay Ohri at the DecisionStats blog offers nine additional methods for bringing data into R, from sources including InfoChimps, the Google Prediction API, the World Bank World Development Indicators, Bloomberg Market Data, and much ... [Read more...]

Using Emacs as a front-end for R

August 15, 2011 | David Smith

Back when I was a grad student, I was a devoted Emacs user. I basically used it like an operating system: it wasn't just my text editor, but also my mail reader, my Web browser, my news reader, and so much more. (I once even asked our sysadmin to change ... [Read more...]

Paul Murrell on Incorporating Images in R Charts

July 13, 2011 | David Smith

Thanks to everyone at who attended last night's Bay Area R User Group meeting, and a special thanks to our hosts Socialize (a company that makes a mobile SDK for application developers that increases user engagement) who were very generous in letting the group use their San Francisco digs for ... [Read more...]

High-quality R graphics on the Web with SVG

July 7, 2011 | David Smith

If you want the graphics you create with R to look their best, in general it's best to go for a vector-based graphics format instead of a raster-based format. Common formats like GIF and JPG are raster-based: the image is composed of pixels, and if you don't choose a high ... [Read more...]

Speed up R "for" loops 50x with Rcpp

June 23, 2011 | David Smith

Christian Gunning has a great example of using Rcpp to speed up a for loop in R. For his agent-based simulation, Christian needed to repeatedly call the rbinom function in a loop. (Unfortunately, you can't pass a vector to the size argument, which would have solved the problem.) Using the ... [Read more...]

Tricks to manage memory in an R session

January 31, 2011 | David Smith

Unless you're using an out-of-memory solution to manage large data objects (such as the RevoScaleR package in Revolution R Enterprise), then R always allocates memory for every object in your working session. If you're working with many objects (or even just a few large objects) then you'll need to take ... [Read more...]

How to create PDF reports with R

December 1, 2010 | David Smith

Sweave is a literate programming system included with R. It makes it possible to create a PDF document containing not just text, but also tables and charts generated from R. The process is automated, so once you've created an Sweave document (which includes both LaTeX text markup and R commands), ... [Read more...]

Loops in R: Think different

November 15, 2010 | David Smith

Especially for programmers that come to R from other languages, R sometimes gets dinged about the speed of its for loops. But a lot of the time, where you might have needed an iterative loop in another language to solve a specific task, you don't need a for loop in ... [Read more...]

R Cookbook

October 27, 2010 | David Smith

Following up on the successful "R in a Nutshell", O'Reilly has just published a new book on R, The R Cookbook, by Paul Teetor. Here's the description: Perform data analysis with R quickly and efficiently using the task-oriented recipes in this cookbook. The R language and environment include everything necessary ... [Read more...]

How to generate correlated random numbers

September 1, 2010 | David Smith

We've covered how to generate random numbers in R before, but what if you want to go beyond generating one random number at a time? What if you want to generate two, or three or more random numbers, and what's more, you want them to be correlated? JD Long lays ... [Read more...]

Connecting Revolution R to MySQL on Windows

June 4, 2010 | David Smith

My colleague Saar Golde was having some troubles connecting Revolution R to MySQL on Windows (64-bit). Turned out the problem was the lack of an environment variable. He documented the instructions for fixing the problem on Windows 7, below. Thanks, Saar! The Problem: A client is about to send me a ... [Read more...]

An economist explains: Why I use R

May 10, 2010 | David Smith

Economist and R blogger JD Long gave a talk last week (as part of the project) about why he uses R to do statistical forecasts of agricultural yield for the reinsurance company he works for. I couldn't make the live session, but a replay is now available. The ... [Read more...]
1 2

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)