![]()
![]()
Copyright Š 2016 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: October 2016
Production reference: 1181016
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78588-977-6
www.packtpub.com
![]()
![]()
Kun Ren has used R for nearly 4 years in quantitative trading, along with C++ and C#, and he has worked very intensively (more than 8-10 hours every day) on useful R packages that the community does not offer yet. He contributes to packages developed by other authors and reports issues to make things work better. He is also a frequent speaker at R conferences in China and has given multiple talks. Kun also has a great social media presence. Additionally, he has substantially contributed to various projects, which is evident from his GitHub account:
- https://github.com/renkun-ken
- https://cn.linkedin.com/in/kun-ren-76027530
- http://renkun.me/
- http://renkun.me/formattable/
- http://renkun.me/pipeR/
- http://renkun.me/rlist/
I would like to thank my wife, who encouraged me to start working on this book a year ago, and my parents, who support me with unconditional love. I would also like to express my gratitude to the editors, Rohit Kumar Singh, Vivek Pala, and those who also worked hard on this book. They did a great job making the writing and publishing smooth.
![]()
Kelly Black is a member of the department of mathematics at the University of Georgia. His focus is stochastic differential equations, and he makes use of statistical software in a wide range of contexts, ranging from data analysis from Monte Carlo simulations to educational assessment.
I am grateful for the kindness and patience of Izzat Contractor, who helped guide the final production of this book.
![]()
For support files and downloads related to your book, please visit www.PacktPub.com.
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at
www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at
[email protected] for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
https://www.packtpub.com/mapt
Get the most in-demand software skills with Mapt. Mapt gives you full access to all Packt books and video courses, as well as industry-leading tools to help you plan your personal development and advance your career.
- Fully searchable across every book published by Packt
- Copy and paste, print, and bookmark content
- On demand and accessible via a web browser
![]()
R is designed for statistical computing, data analysis, and visualization. In recent years, it has become the most popular language for data science and statistics. R programming heavily involves data processing and it can be a challenge to program in R for those who are unfamiliar with the behaviors of the R language.
As a dynamic language, R allows extremely flexible use of data structures that are not as strict as compiled languages, such as C++, Java, and C#. When I started using R to process and analyze data, I found Râs behavior quirky, unpredictable, and sometimes very inconsistent.
In those data analysis projects, most effort was not spent running models. Instead, data cleaning, wrangling, and visualization took a major part of my time. In fact, it is most time consuming to find whatâs wrong with the code that produced weird results or died in unexpected errors. Dealing with programming rather than field problems can be frustrating, especially when you have fought against bugs for hours without a clue.
However, as I work on more projects and gain more experience, I gradually know more about the behavior of objects and functions, and find that R is much more beautiful and consistent than I thought. Thatâs why I've written this bookâto share my perspective on programming in R.
Through this book, you will develop a universal and consistent understanding of R as a programming language along with its vast set of tools. You will learn the best practices to boost your productivity, develop a deeper understanding of working with data, and become more confident about programming in R and solving problems with the right techniques.
Chapter 1, Quick Start, discusses a few basic facts about R, how to deploy an R environment, and how to code in RStudio.
Chapter 2, Basic Objects, introduces basic R objects and their behaviors.
Chapter 3, Managing Your Workspace, introduces the methods of managing the working directory, R environment, and the library of extension packages.
Chapter 4, Basic Expressions, covers the basic expressions of the R language: assignment, condition, and loop.
Chapter 5, Working with Basic Objects, discusses the basic functions each analyst should know in order to work with basic objects in R.
Chapter 6, Working with Strings, talks about R objects related with strings, and a number of string manipulation techniques.
Chapter 7, Working with Data, explains simple read/write data functions with some practical examples on various topics using basic objects and functions.
Chapter 8, Inside R, discusses Râs evaluation model by introducing what lazy evaluation, environment, function, and lexical scoping work is.
Chapter 9, Metaprogramming, introduces the metaprogramming techniques to help understand language objects and nonstandard evaluation.
Chapter 10, Object-Oriented Programming, describes the numerous object-oriented programming systems in R: S3, S4, RefClass, and community-provided R6.
Chapter 11, Working with Databases, shows how R works with popular relational databases such as SQLite and MySQL, and non-relational databases such as MongoDB and Redis.
Chapter 12, Data Manipulation, introduces techniques of manipulating relational data using data.table and dplyr, and non-relational data using rlist.
Chapter 13, High Performance Computing, discusses performance issues in R and several methods to boost computing performance.
Chapter 14, Web Scraping, talks about the basic structure of web pages, CSS, and XPath selectors and how to use the rvest package to scrape data from simple web pages.
Chapter 15, Boosting Productivity, demonstrates how R Markdown an...