Introduction to R

R is an open-source software that is commonly used by statisticians and researchers in both academic and commercial settings. The reader can download R for free at the Comprehensive R Archive Network. We also recommend the download of RStudio, which is a free, integrated development environment for R, and provides a user-friendly interface for R. Below are instructions on how to download both R and RStudio.

We also offer a few different ways that are user-friendly for loading data from an Excel spreadsheet into RStudio. The R-code we provide for each statistical methodology can be used by the researcher on their own data by simply loading their data into R and replacing the data in our examples with their own.

One advantage of using the software R is that the code can be modified using a multitude of available options to meet the user’s needs. Moreover, R has the ability to produce high quality, publication-ready graphs that the reader can also customize. The reader will find multiple options for several examples provided in this handbook, and can decide to take advantage of the different options to customize their R-code output or the settings of their graph. The code for several of these options included in the examples has been made inactive by introducing the symbol “#” at the beginning of the line of code, and it can be activated again by simply deleting this symbol. More options for each statistical method or plot can be found in the Help tab in RStudio.

This website provides the R-code for the many methodologies and examples used in our handbook, and thus makes the programming aspect of a research project accessible to the user without extensive experience with R. For additional applications, the reader can consult the vast library of packages and examples for R-code that is freely available online (see for example https://stackoverflow.com/).


Installing R and RStudio

You need to first download R and then download and install RStudio. It is important to note that these instructions are for installing R and RStudio for the first time. If you already have these installed, we recommend uninstalling them and then following the procedure below.

To install R

For Windows:

  1. Go to http://www.r-project.org
  2. Click on Download R
  3. Choose a CRAN mirror site (choose a site near your location)
  4. Choose “Download R for Windows”
  5. Click “Install R for the First Time”
  6. Run executable .exe file and follow installation instructions.

For Mac:

  1. Go to http://www.r-project.org
  2. Click on Download R
  3. Choose a CRAN mirror site (choose a site near your location)
  4. Choose “Download R for Mac”
  5. Save the .pkg file, double click it to open and follow installation instructions.

To install RStudio

  1. Go to https://rstudio.com/products/rstudio/download/
  2. Click on Download Free RStudio Desktop
  3. Choose Windows or Mac version (.exe for Windows and .dmg for Mac)
  4. Save file, double click it and follow installation instructions.

Loading Data into RStudio from Excel

There are several ways to load data into RStudio, we provide three easy ways below:

(1) Using Copy-Paste Method with Commas: Video
(2) Using Copy-Paste Method Using Data Frame: Video
(3) Using Import Function in RStudio: Video

Method (1) and (2) are user-friendly and useful for small one-column data sets. Method (3) is the most flexible as it applies to large data sets with numerous columns.

R-code for Method (2):

PastedData<-
"72.55
74.16
73.8
71.72
74.21
74.85
74.67
72.82
72.9
73.96
74.26
73.9
72.89
74.56"

#dframe<-read.delim(text=PastedData,sep="\n")
dframe<-read.delim(text=PastedData,sep="\n",header=FALSE)
dframe
luminosity<-dframe[,1]

hist(luminosity)

R-code for Statistical Methods

  1. QQplot
  2. Histogram
  3. One-Group z-test
  4. One-Group t-test
  5. Two-Group z-test
  6. Two-Group paired t-test
  7. F-test to check equality of variance
  8. Two-Group pooled t-test
  9. Two-Group unpooled t-test
  10. ANOVA Tukey Method
  11. ANOVA Bonferroni Method
  12. ANOVA Scheffé Method
  13. Visualizing Scatterplot for Regression
  14. Regression Analysis
  15. Mann Whitney U Test
  16. Sign Test and Wilcoxon Signed Rank Test
  17. Kruskal Wallis Test
  18. Two Factor ANOVA Example 1
  19. Two Factor ANOVA Example 2

Previous Page | Next Page