# The CShapes R Package

R is a free statistical software package, available from http://cran.r-project.org/. Once R is running on your system, you can use the built-in package manager to install the cshapes package:

- Install R from CRAN.
- Install the cshapes package using R's package manager. Alternatively, type

*> install.packages("cshapes", dependencies = TRUE)*

on the R console. This will also install other R extensions required by cshapes.

### Using CShapes from R

The following R code loads the cshapes package, creates a matrix with distances between country capitals for the international system in 2002 and writes the matrix to a file. The rows and columns in this matrix are labeled with codes according to the Gleditsch & Ward system. If you need COW codes, add the `useGW=F`

option to the distmatrix() call.

` library(cshapes)`

dmat <- distmatrix(as.Date("2002-1-1"), type="capdist")

write.table(dmat, "distmat2002.txt", row.names=T, col.names=T)

Many applications require an adjacency matrix, which can be created from the distance matrix. Here, we code all countries to be adjacent if their capital distance does not exceed 900 km.

`adjmat <- ifelse(dmat > 900, 0, 1)`

diag(adjmat) <- 0

write.table(adjmat, "adjmat2002.txt", row.names=T, col.names=T)

### Examples

Here you can find a set of examples for using R with cshapes. We will keep posting new examples as we get them.

### Additional Information

Other examples of using the cshapes R package can be found in our R Journal article.

### CShapes on R-Forge

The CShapes development site is hosted on R-Forge.