R for Programmes

By George Ross Ihaka
284
2026

Description

The aim of The Book R For Programmes is to provide a relatively gentle yet informative exposure to the statistical software environment R, alongside some common statistical analyses, so that readers may have a solid foundation from which to eventually become experts in their own right. Learning to use and program in a computing language is much the same as learning a new spoken language. At the beginning, it is often difficult and may even be daunting but total immersion in and active use of the language is the best and most effective way to become fluent. Many beginner-style texts that focus on R can generally be allocated to one of two categories: those concerned with computational aspects (that is, syntax and general programming tools) and those with statistical modeling and analysis in mind, often one particular type. In my experience, these texts are extremely well written and contain a wealth of useful information but better suit those individuals wanting to pursue fairly specific goals from the outset. This text seeks to combine the best of both worlds, by first focusing on only an appreciation and understanding of the language and its style and subsequently using these skills to fully introduce, conduct, and interpret some common statistical practices. The target audience is, quite simply, anyone who wants to gain a foothold in R as a first computing language, perhaps with the ultimate goal of completing their own statistical analyses. The book covers various aspects of R, from basic syntax to advanced techniques like machine learning and creating functions and simulations. This book is a good choice for beginners and those looking to delve into advanced analytics and graphics using R. This book offers a comprehensive introduction to programming and statistics using R, suitable for a first course, focuses on practical skills, teaching you how to write your own functions and perform simulations in R. The book deals with the heart of the R language and its fundamental concepts, including data organization, import and export, various manipulations, documentation, plots, programming and maintenance. The R programming language has become the de facto programming language for data science. Its flexibility, power, sophistication, and expressiveness have made it an invaluable tool for data scientists around the world. This book is about the fundamentals of R programming. You will get started with the basics of the language, learn how to manipulate datasets, how to write functions, and how to debug and optimize code. With the fundamentals provided in this book, you will have a solid foundation on which to build your data science toolbox. R For Programmes can be used purely as a programming text to learn the language or as an introductory statistical methods book with accompanying instruction in R. Though it is not intended to represent an exhaustive dictionary of the language, the aim is to provide readers with a comfortable learning tool. The fact remains that there are usually many different ways to go about any given task something that holds true for most so-called high-level computer languages.

About Author

George Ross Ihaka is an associate professor of statistics at the University of Auckland. In 2008, Ihaka received the Pickering Medal, awarded by the Royal Society of New Zealand, for his work on R. Ihaka completed his undergraduate education at the University of Auckland, and obtained his PhD in 1985 from the University of California. His thesis was on statistical modelling for seismic interferometry and was titled Rūaumoko, after the god of earthquakes, volcanoes and seasons in Maori mythology. He is working on a new statistical programming language based on Lisp. He is a member of the Weka project, New Zealand's other famous open-source data science contribution, and here talks about the design and development of Weka and more recent projects.

Table of Content

Preface
Chapter 1. Introduction to R

What is R Programming?
History and Evolution of R
Installing R and RStudio
R vs Other Languages (Python, SAS, etc.)

Chapter 2. Data Types and Variables
Numeric, Integer, Complex, Logical, and Character Types
Vectors and Vector Operations
Factors and Their Use in Categorical Data
Lists and Named Elements
Matrices and Matrix Arithmetic

Chapter 3. Control Structures
Conditional Statements (if, else, ifelse)
Switch Statement
Break and Next Statements
Apply Family Functions (apply, lapply, sapply)

Chapter 4. Functions in R
Defining and Calling Functions
Function Arguments and Default Values
Return Statements
Scope of Variables (Global vs Local)
Anonymous Functions and Lambda Expressions

Chapter 5. Data Input and Output
Reading CSV and TXT Files (read.csv, read.table)
Writing Data to Files (write.csv, write.table)
Reading Excel Files with readxl
Importing JSON and XML
Reading from Web and APIs
Saving and Loading R Data Objects (save, load, RDS)

 

Chapter 6. Data Structures and Manipulation
Data Frames and Basic Operations
Subsetting Data (rows, columns, conditions)
Merging and Joining Data Frames
Sorting and Filtering Data

Chapter 7. Data Cleaning and Preprocessing
Handling Missing Values (NA, NaN, NULL)
Duplicates and Data Deduplication
Data Transformation (scaling, normalization)
Text Cleaning and String Manipulation

Chapter 8. Data Visualization in R
Base R Plotting System (plot, hist, boxplot)
ggplot2 Basics: Grammar of Graphics
Customizing Plots (themes, scales, legends)
Bar Charts, Pie Charts, and Line Graphs

Chapter 9. Working with Tidyverse
Introduction to the Tidyverse Ecosystem
dplyr for Data Manipulation (filter, mutate)
tidyr for Data Tidying (pivot_longer, pivot_wider)
stringr for Text Operations

Bibliography