Category Archive

The following is a list of all entries from the R category.

Querying Postgres or Greenplum From R on a Mac, Installation Instructions

NB: this works on 64b versions of R; I tested it with the R64 app with R version 2.10.1 on Snow Leopard
Step by step instructions for talking to Postgres or Greenplum:

install macports
install postgres; I used 8.4

sudo port install postgresql84

in a shell, create an environmental variable PG_CONFIG pointing to the pg_config binary installed [...]


Querying Databases From R on a Mac

I use a mac, currently running OS 10.6 / Snow Leopard, and I’d like to query our greenplum / postgres database from R. This used to work with R 2.9, but I unfortunately had to upgrade R, and R 2.10 on the mac is a 64 bit app. So, I want to use [...]


Querying Postgres or Greenplum from R on a Mac

So, I’m using snow leopard, and I want to query our postgres / greenplum database.
First things first: I’m familiar with the RODBC package on CRAN. This installs fine, since it’s a binary package. I also installed the ODBC Administrator app that you have to download from apple here . Now all [...]


Plotting in Grids

This is post #12 in a running series about plotting in R.

I regularly find myself wanting to show arrays or grids of plots in R. This is straightforward using par and mfrow as long as you want a symmetric, evenly spaced grid of plots. Unfortunately, this often is not what I [...]


Querying Databases in R

One of the first things you’ll want to do in R is set it up to talk to databases. The easiest way to do this is using ODBC, via package RODBC.
To get the package, run

> install.packages(RODBC)

Once you have RODBC installed, you call it in R as follows. But it’s very simple: a bit [...]


R Dates – Recovering and Converting From Integers

One problem with R is that dates (class Date) are internally stored as integer numbers of days elapsed since 1 January 1970 and R sometimes loses the dateness of the variables and thinks of it only as an integer. So in the first line, we take the range of dates present in our data, [...]


Shading Pieces of an R Plot

This is post #11 in a running series about plotting in R.

I often want to shade pieces of an R plot, in order to visually draw out some piece, such as weekends or recessions. Let’s look at how to do that with the plain plotting tools.
First, I have some obscured data from [...]


Examining Data Frames — head and tail

head and tail, for those familiar with the unix command line, are two very handy utilities for looking at data frames. Along with str, which displays the structure of a data frame, they help you look at your data:

> d d
> str(d)
‘data.frame’: 50 obs. of 2 variables:
$ mean: int 1 [...]


Filled Line Plots / Graphs in R — Part 10 in a Series

This is post #10 in a running series about plotting in R.

Otherwise known as filled curves.
Say you want to, instead of drawing a single line, draw a filled curve. R’s basic plot doesn’t make the especially easy, though it can be made much easier with packages such as ggplot2 as we’ll see [...]


Multiple Y Axes in R Plots — Part 9 in a Series

This is post #09 in a running series about plotting in R.

Frequently, you want to plot data that is not at all on the same scale. In R, this is done via plotting a second graph on top of your first and building the axes labels by hand. Here’s a rough [...]