R Programming by Example
Book information
Description
Contents......Page 3 Preface......Page 11 What R is and what it isn't......Page 17 R is a high quality statistical computing system......Page 18 R is free, as in freedom and as in free beer......Page 19 Comparing R with other software......Page 20 The interpreter and the console......Page 21 Pick an IDE or a powerful editor......Page 24 The send to console functionality......Page 25 The efficient write-execute loop......Page 26 Executing R code in non-interactive sessions......Page 27 How to use this book......Page 29 Tracking state with symbols and variables......Page 30 Working with data types and data structures......Page 31 Special values......Page 32 Characters......Page 33 Logicals......Page 35 Vectors......Page 37 Factors......Page 41 Matrices......Page 43 Lists......Page 46 Data frames......Page 49 Divide and conquer with functions......Page 51 Functions as arguments......Page 54 Operators are functions......Page 56 Complex logic with control structures......Page 57 If… else conditionals......Page 58 For loops......Page 60 While loops......Page 63 The examples in this book......Page 64 Summary......Page 65 Chapter 2: Understanding Votes with Descriptive Statistics......Page 66 The Brexit votes example......Page 67 Cleaning and setting up the data......Page 69 Summarizing the data into a data frame......Page 72 Visualizing variable distributions......Page 77 Using matrix scatter plots for a quick overview......Page 81 Getting a better look with detailed scatter plots......Page 82 Understanding interactions with correlations......Page 86 Creating a new dataset with what we've learned......Page 87 Building new variables with principal components......Page 89 Planning before programming......Page 93 Understanding the fundamentals of high-quality code......Page 94 Programming by visualizing the big picture......Page 96 Summary......Page 103 Chapter 3: Predicting Votes with Linear Models......Page 105 Setting up the data......Page 106 Training and testing datasets......Page 107 Predicting votes with linear models......Page 108 Checking model assumptions......Page 111 Checking linearity with scatter plots......Page 112 Checking normality with histograms and quantile-quantile plots......Page 113 Checking homoscedasticity with residual plots......Page 116 Checking no collinearity with correlations......Page 118 Measuring accuracy with score functions......Page 120 Generating model combinations......Page 122 Summary......Page 129 Chapter 4: Simulating Sales Data and Working with Databases......Page 130 Designing our data tables......Page 131 Simplifying assumptions......Page 132 The too-much-empty-space problem......Page 133 The too-much-repeated-data problem......Page 134 Simulating the sales data......Page 136 Simulating numeric data according to distribution assumptions......Page 137 Simulating categorical values using factors......Page 139 Simulating numbers under shared restrictions......Page 140 Simulating strings for complex identifiers......Page 142 Putting everything together......Page 144 Simulating the client data......Page 148 Simulating the client messages data......Page 150 Working with relational databases......Page 153 Summary......Page 158 Chapter 5: Communicating Sales with Visualizations......Page 159 Extending our data with profit metrics......Page 160 Building blocks for reusable high-quality graphs......Page 161 Starting with simple applications for bar graphs......Page 163 Adding a third dimension with colors......Page 167 Graphing top performers with bar graphs......Page 170 Graphing disaggregated data with boxplots......Page 172 Pricing and profitability by protein source and continent......Page 174 Client birth dates, gender, and ratings......Page 176 Developing our own graph type – radar graphs......Page 179 Exploring with interactive 3D scatter plots......Page 184 Looking at dynamic data with time-series......Page 186 Looking at geographical data with static maps......Page 189 Maps you can navigate and zoom-in to......Page 191 High-tech-looking interactive globe......Page 194 Summary......Page 198 Chapter 6: Understanding Reviews with Text Analysis......Page 199 This chapter's required packages......Page 200 What is text analysis and how does it work?......Page 201 Preparing, training, and testing data......Page 203 Building the corpus with tokenization and data cleaning......Page 205 Document feature matrices......Page 208 Training our first predictive model......Page 210 Improving speed with parallelization......Page 212 Computing predictive accuracy and confusion matrices......Page 213 Improving our results with TF-IDF......Page 214 Adding flexibility with N-grams......Page 217 Reducing dimensionality with SVD......Page 219 Extending our analysis with cosine similarity......Page 221 Digging deeper with sentiment analysis......Page 222 Testing our predictive model with unseen data......Page 224 Retrieving text data from Twitter......Page 227 Summary......Page 229 Chapter 7: Developing Automatic Presentations......Page 230 Why invest in automation?......Page 231 Literate programming as a content creation methodology......Page 232 Reproducibility as a benefit of literate programming......Page 233 The basic tools for an automation pipeline......Page 234 A gentle introduction to Markdown......Page 235 Headers......Page 236 Lists......Page 237 Tables......Page 238 Images......Page 239 Code......Page 240 Code chunks......Page 241 Tables......Page 242 Graphs......Page 243 Caching......Page 244 Producing the final output with knitr......Page 245 Developing graphs and analysis as we normally would......Page 246 Building our presentation with R Markdown......Page 256 Summary......Page 263 Chapter 8: Object-Oriented System to Track Cryptocurrencies......Page 264 The cryptocurrencies example......Page 265 A brief introduction to object-oriented programming......Page 266 The purpose of object-oriented programming......Page 267 Encapsulation......Page 268 Polymorphism......Page 269 Classes and constructors......Page 270 Public and private methods......Page 271 Interfaces, factories, and patterns in general......Page 272 The first source of confusion – various object models......Page 273 The second source of confusion – generic functions......Page 274 Classes, constructors, and composition......Page 275 Public methods and polymorphism......Page 276 Encapsulation and mutability......Page 279 Inheritance......Page 281 The S4 object model......Page 282 Classes, constructors, and composition......Page 283 Public methods and polymorphism......Page 284 Encapsulation and mutability......Page 286 Inheritance......Page 288 Classes, constructors, and composition......Page 289 Encapsulation and mutability......Page 292 Inheritance......Page 293 Active bindings......Page 294 The architecture behind our cryptocurrencies system......Page 295 Starting simple with timestamps using S3 classes......Page 300 Implementing cryptocurrency assets using S4 classes......Page 303 Implementing our storage layer with R6 classes......Page 304 Communicating available behavior with a database interface......Page 305 Implementing a database-like storage system with CSV files......Page 306 Easily allowing new database integration with a factory......Page 313 Encapsulating multiple databases with a storage layer......Page 314 Creating a very simple requester to isolate API calls......Page 316 Developing our exchanges infrastructure......Page 317 Developing our wallets infrastructure......Page 321 Implementing our wallet requesters......Page 322 Finally introducing users with S3 classes......Page 326 Helping ourselves with a centralized settings file......Page 328 Saving our initial user data into the system......Page 330 Activating our system with two simple functions......Page 331 Some advice when working with object-oriented systems......Page 334 Summary......Page 335 Chapter 9: Implementing an Efficient Simple Moving Average......Page 336 Required packages......Page 337 Starting by using good algorithms......Page 338 Just how much impact can algorithm selection have?......Page 339 Calculating simple moving averages inefficiently......Page 342 Simulating the time-series ......Page 344 Our first (very inefficient) attempt at an SMA......Page 346 Understanding why R can be slow......Page 349 Object immutability......Page 350 Memory-bound processes......Page 351 Single-threaded processes......Page 352 Profiling fundamentals with Rprof()......Page 353 Benchmarking manually with system.time()......Page 355 Benchmarking automatically with microbenchmark()......Page 356 Using the simple data structure for the job......Page 358 Vectorizing as much as possible......Page 361 Removing unnecessary logic......Page 364 Moving checks out of iterative processes......Page 365 If you can, avoid iterating at all......Page 367 Using R's way of iterating efficiently......Page 369 Avoiding sending data structures with overheads......Page 371 Using parallelization to divide and conquer......Page 373 How deep does the parallelization rabbit hole go?......Page 374 Practical parallelization with R......Page 375 Using C++ and Fortran to accelerate calculations......Page 378 Using an old-school approach with Fortran......Page 379 Using a modern approach with C++......Page 383 Looking back at what we have achieved......Page 387 Preallocating memory to avoid duplication......Page 389 Just-in-time (JIT) compilation of R code......Page 390 Improving our data and memory management......Page 391 Using specialized packages for performance......Page 392 Summary......Page 393 Chapter 10: Adding Interactivity with Dashboards......Page 395 Introducing the Shiny application architecture and reactivity......Page 396 What is functional reactive programming and why is it useful?......Page 397 The building blocks for reactivity in Shiny......Page 399 The input, output, and rendering functions......Page 400 Designing our high-level application structure......Page 402 Setting up a two-column distribution......Page 403 Introducing sections with panels......Page 404 Inserting a dynamic data table......Page 405 Setting up static user inputs......Page 407 Setting up dynamic options in a drop-down......Page 410 Setting up dynamic input panels......Page 412 Adding a summary table with shared data......Page 415 Adding a simple moving average graph......Page 417 Adding interactivity with a secondary zoom-in graph......Page 421 Styling our application with themes......Page 424 Adding static images......Page 430 Adding custom CSS styling......Page 431 Sharing your newly created application......Page 432 Summary......Page 433 External requirements – software outside of R......Page 434 macOS High Sierra......Page 436 Setting up user/password in both Linux and macOS......Page 437 Ubuntu 17.10......Page 439 macOS High Sierra......Page 440 Internal requirements – R packages......Page 441 Loading R packages......Page 445 Index......Page 446
Similar books
Mastering Rust
2019 · EPUB
Programowanie w JavaScript. Rusz głową!
2015 · PDF
JavaScript. Zasady programowania obiektowego
2014 · PDF
Learning C++ Functional Programming
2017 · EPUB
Beginning C++ Programming
2018 · EPUB
An Introduction to Programming in Go
2012 · EPUB
R Programming By Example
2017 · EPUB
R Programming By Example: Practical, hands-on projects to help you get started with R (English Edition)
2017 · PDF