There are a large of number of software packages that are available for data analysts and the foreign package in R has functions defined to read data from some of the most commonly used packages that have their own proprietary data format. For other packages the user can often export data to a delimited text file which can then be handled easily by R.
To make use of the foreign package we first need to attach it to our session in the usual way for R packages:
library(foreign) |
Stata
The Stata software package has a binary format for representing data and the file name has an extension of dta. There is a function called read.dta in the foreign library that can be used to import data from these binary files. As an example if we wanted to load some data we could run the following code:
read.dta("Data\\reactor.dta") |
This function call is very straightforward and we would save the output to a data frame of our choice so that it can be used for the subsequent analysis.
Minitab
Another popular statistical software package is Minitab and we can import data saved in the Minitab Portable Worksheet format. If the data in the example above had been exported from Minitab then the function call to load the data would be:
read.mtp("Data\\reactor.mtp") |
SPSS
Another frequently used package is SPSS and as with the other packages there is a function that can be used to import data from an sav file. The syntax for this operation is very similar to the functions for importing data from other systems:
read.spss("Data\\test-results-data.sav") |
There are other file formats that can be handled by the foreign library but these will not be considered in this post.