Let’s Use R Now…

A. Jonathan R. Godfrey

May 7, 2017
ISBN 978-0-473-17650-1

Please include the following details when citing this publication as a single volume.


Godfrey, A. Jonathan R.




LURN: Let’s Use R Now


Institute of Fundamental Sciences, Massey University


Palmerston North, New Zealand

ISBN 978-0-473-17650-1

This e-text is made available for education purposes without any claim for financial recompense from the author. It is however intended that any use of the e-text, whether wholly or in part, be done with all parties being aware that the work is made available to any third party under the same conditions as placed on this volume.

1 What’s this all about?
 1.1 Getting started
 1.2 Versions of R
2 LURN… To Work R Blind
 2.1 Screen readers
 2.2 R and braille displays
 2.3 Setting up R as a blind Windows user
 2.4 Setting up R as a blind Mac user
 2.5 Setting up R as a blind Linux user
 2.6 Getting the most out of the R window
 2.7 More advanced ways of running R programs
3 LURN… To Enter Data
 3.1 Using R as a simple calculator
 3.2 A simple set of numbers
 3.3 A simple set of text values
 3.4 Logical indicators
 3.5 A note on subscripting
 3.6 A patterned set of numbers
 3.7 Less pattern and more repetition
 3.8 An incomplete pattern
 3.9 Dates and times
 3.10 Larger data objects
 3.11 Appropriate data labelling
 3.12 Other approaches
4 LURN… To Import Data
 4.1 Data from external files
 4.2 Data stored in another directory
 4.3 Data saved by other statistical software
 4.4 Data from files stored on the internet
 4.5 Data contained in contributed packages
 4.6 Data cleanliness
 4.7 Other packages
5 LURN… To Manipulate your Datasets
 5.1 Sorting the data into a different order
 5.2 Extracting data using information on one variable
 5.3 Extracting data using information on more than one variable
 5.4 Use of dplyr for data manipulation
6 LURN… To Export a Dataset
 6.1 Creating external files
 6.2 Exporting data for use in alternative software
7 LURN… To Create Simple Graphs
 7.1 Histograms
 7.2 Basic annotations to graphs
 7.3 Other univariate summary graphs
 7.4 Quantile-quantile plots
 7.5 Scatter plots
 7.6 Scatter plot matrices
 7.7 Graphs for discrete valued variables
 7.8 Closing
8 LURN… To Examine Data Numerically
 8.1 Obtaining basic numerical summaries of data
 8.2 Obtaining slightly more elegant summaries
 8.3 Getting things printed how we want them
 8.4 Correlation structure within a data set
 8.5 Use of dplyr for data summarisation
 8.6 Closing
9 LURN… To Save Results for Later Inspection
 9.1 Copying and pasting graphs
 9.2 Saving a graph using the menus
 9.3 Saving a graph using commands within your R program
 9.4 Saving output in a text file
 9.5 Saving the entire R Console
10 LURN… To Become More Efficient in your Workplace
 10.1 Managing R when you have multiple projects on the go
 10.2 Batch processing commands
 10.3 Running an R script without opening R under Windows
 10.4 Using file associations in Windows
 10.5 Don’t re-invent any wheels
11 LURN… To Do Basic Inference
 11.1 Confidence intervals and hypothesis tests for the mean of one population
 11.2 Confidence intervals and hypothesis tests for the difference of two population means
 11.3 Confidence intervals and hypothesis tests for a proportion from one population
 11.4 Confidence intervals and hypothesis tests for the difference of two population proportions
 11.5 Hypothesis tests and confidence intervals for Correlation coefficients
 11.6 Testing the independence of two categorical variables
 11.7 Testing the normality of a distribution
12 LURN… To Perform Regression Analyses
 12.1 Data and suitable exploratory graphs
 12.2 The simple regression model
 12.3 Presenting the straight line model’s suitability in a graph
 12.4 Model validation using diagnostic plots
 12.5 Polynomial regression models
 12.6 Presenting the polynomial model’s suitability in a graph
 12.7 Multiple regression models
 12.8 Indicator variables
13 LURN… To Create Complex Graphs
 13.1 More than one graph in a single window
 13.2 Allowing different sized graphs to be included in a single window
 13.3 Using colour or different symbols
 13.4 Adding points to an existing graph
 13.5 Using lines instead of points
 13.6 Adding lines to an existing graph
 13.7 Adding a curve to a graph
 13.8 Adding text to an existing graph
 13.9 Adding a legend for different information within a graph
 13.10 More complex bar charts
 13.11 Contour plots
14 Extending R beyond the base installation
 14.1 Installing additional packages
 14.2 Updating add-on packages
 14.3 Using an enhanced graphical interface
 14.4 Use of an integrated development environment (IDE)
15 LURN… To use the BrailleR add-on package
 15.1 Creating a copy of the R console window
 15.2 Text interpretation of graphs
 15.3 Basic descriptions of variables
 15.4 Altering R output to make it easier to read
 15.5 Reading a scatter plot
 15.6 What else?
16 LURN… To create maps
 16.1 Creation of maps
 16.2 Adding cities to a map
 16.3 Using Google’s services to map locations of interest
17 LURN… To Use R as a Scientific Calculator
 17.1 Trigonometric functions
 17.2 Graphs of trigonometric functions
18 LURN… To Use R for Basic Calculus Tasks
 18.1 Creating mathematical expressions
 18.2 Plotting functions
 18.3 Differentiation
19 LURN… To Use R for Linear Algebra
 19.1 Basic notes on storage of vectors and matrices
 19.2 Creating some simple matrix structures
 19.3 Matrix and vector calculations
 19.4 Inverting a matrix
 19.5 Solving a set of linear equations
 19.6 Determinants and traces
 19.7 Eigenvalues and eigenvectors
20 LURN… To Solve Operations Research Problems
 20.1 The Assignment Problem
 20.2 The transportation problem