ebook img

Learning Modular Java Programming PDF

571 Pages·2016·8.721 MB·english
by  Kun Ren
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Learning Modular Java Programming

Learning R Programming Become an efficient data scientist with R Kun Ren Learning R Programming Copyright © 2016 Packt Publishing 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 Contents Preface 1 Chapter 1: Quick Start 7 Introducing R 7 R as a programming language 8 R as a computing environment 8 R as a community 9 R as an ecosystem 9 The need for R 10 Installing R 12 RStudio 15 RStudio's user interface 16 The console 16 The editor 17 The Environment pane 18 The History pane 19 The File pane 19 The Plots pane 20 The Packages pane 20 The Help pane 21 The Viewer pane 22 RStudio Server 23 A quick example 23 Summary 25 Chapter 2: Basic Objects 26 Vector 27 Numeric vector 27 Logical vector 29 Character vector 30 Subsetting vectors 32 Named vectors 34 Extracting an element 36 Telling the class of vectors 37 Converting vectors 37 Arithmetic operators for numeric vectors 39 Matrix 40 Creating a matrix 40 Naming rows and columns 41 Subsetting a matrix 41 Using matrix operators 43 Array 45 Creating an array 45 Subsetting an array 46 Lists 47 Creating a list 47 Extracting an element from a list 48 Subsetting a list 49 Named lists 50 Setting values 50 Other functions 52 Data frames 53 Creating a data frame 53 Naming rows and columns 54 Subsetting a data frame 55 Subsetting a data frame as a list 55 Subsetting a data frame as a matrix 56 Filtering data 58 Setting values 59 Setting values as a list 59 Setting values as a matrix 60 Factors 60 Useful functions for data frames 61 Loading and writing data on disk 63 Functions 64 Creating a function 65 Calling a function 65 Dynamic typing 65 Generalizing a function 66 Default value for function arguments 69 Summary 69 Chapter 3: Managing Your Workspace 70 R's working directory 70 Creating an R project in RStudio 71 Comparing absolute and relative paths 72 Managing project files 73 Inspecting the environment 74 [ ii ] Inspecting existing symbols 75 Viewing the structure of an object 76 Removing symbols 79 Modifying global options 81 Modifying the number of digits to print 81 Modifying the warning level 82 Managing the library of packages 84 Getting to know a package 85 Installing packages from CRAN 86 Updating packages from CRAN 87 Installing packages from online repositories 88 Using package functions 89 Masking and name conflicts 92 Checking whether a package is installed 94 Summary 95 Chapter 4: Basic Expressions 96 Assignment expressions 96 Alternative assignment operators 97 Using backticks with non-standard names 100 Conditional expressions 103 Using if as a statement 104 Using if as an expression 108 Using if with vectors 110 Using vectorized if: ifelse 112 Using switch to branch values 113 Loop expressions 115 Using the for loop 115 Managing the flow of a for loop 118 Creating nested for loops 120 Using the while loop 121 Summary 122 Chapter 5: Working with Basic Objects 124 Using object functions 124 Testing object types 125 Accessing object classes and types 128 Accessing data dimensions 129 Getting data dimensions 130 Reshaping data structures 131 Iterating over one dimension 133 [ iii ] Using logical functions 133 Logical operators 134 Logical functions 135 Aggregating logical vectors 136 Asking which elements are TRUE 137 Dealing with missing values 138 Logical coercion 140 Using math functions 141 Basic functions 141 Number rounding functions 142 Trigonometric functions 143 Hyperbolic functions 144 Extreme functions 145 Applying numeric methods 147 Root finding 147 Calculus 152 Derivatives 152 Integration 153 Using statistical functions 153 Sampling from a vector 154 Working with random distributions 155 Computing summary statistics 157 Computing covariance and correlation matrix 159 Using apply-family functions 161 lapply 162 sapply 163 vapply 164 mapply 165 apply 166 Summary 167 Chapter 6: Working with Strings 168 Getting started with strings 168 Printing texts 169 Concatenating strings 172 Transforming texts 173 Changing cases 173 Counting characters 174 Trimming leading and trailing whitespaces 175 Substring 176 Splitting texts 177 Formatting texts 178 [ iv ] Using Python string functions in R 180 Formatting date/time 181 Parsing text as date/time 181 Formatting date/time to strings 184 Using regular expressions 186 Finding a string pattern 188 Using groups to extract the data 189 Reading data in customizable ways 191 Summary 193 Chapter 7: Working with Data 194 Reading and writing data 194 Reading and writing text-format data in a file 195 Importing data via RStudio IDE 195 Importing data using built-in functions 196 Importing data using the readr package 197 Writing a data frame to a file 198 Reading and writing Excel worksheets 200 Reading and writing native data files 201 Reading and writing a single object in native format 202 Saving and restoring the working environment 204 Loading built-in datasets 205 Visualizing data 208 Creating scatter plots 208 Customizing chart elements 210 Customizing point styles 210 Customizing point colors 214 Creating line plots 216 Customizing line type and width 216 Plotting lines in multiple periods 218 Plotting lines with points 219 Plotting a multi-series chart with a legend 220 Creating bar charts 222 Creating pie charts 223 Creating histogram and density plots 224 Creating box plots 228 Analyzing data 231 Fitting a linear model 231 Fitting a regression tree 237 Summary 239 Chapter 8: Inside R 241 Understanding lazy evaluation 242 [ v ] Understanding the copy-on-modify mechanism 247 Modifying objects outside a function 251 Understanding lexical scoping 253 Understanding how an environment works 258 Knowing the environment object 258 Creating and chaining environments 259 Accessing an environment 260 Chaining environments 261 Using environments for reference semantics 263 Knowing the built-in environments 264 Understanding environments associated with a function 267 Summary 270 Chapter 9: Metaprogramming 271 Understanding functional programming 271 Creating and using closures 272 Creating a simple closure 272 Making specialized functions 273 Fitting normal distribution with maximal likelihood estimation 274 Using higher-order functions 277 Creating aliases for functions 277 Using functions as variables 278 Passing functions as arguments 279 Computing on language 283 Capturing and modifying expressions 285 Capturing expressions as language objects 285 Modifying expressions 289 Capturing expressions of function arguments 290 Constructing function calls 291 Evaluating expressions 292 Understanding non-standard evaluation 295 Implementing quick subsetting using non-standard evaluation 295 Understanding dynamic scoping 297 Using formulas to capture expression and environment 298 Implementing subset with metaprogramming 301 Summary 303 Chapter 10: Object-Oriented Programming 304 Introducing object-oriented programming 305 Understanding classes and methods 305 Understanding inheritance 305 Working with the S3 object system 306 Understanding generic functions and method dispatch 307 [ vi ] Working with built-in classes and methods 309 Defining generic functions for existing classes 318 Creating objects of new classes 319 Using list as the underlying data structure 319 Using an atomic vector as the underlying data structure 324 Understanding S3 inheritance 327 Working with S4 331 Defining S4 classes 332 Understanding S4 inheritance 336 Defining S4 generic functions 338 Understanding multiple dispatch 341 Working with the reference class 343 Working with R6 345 Summary 348 Chapter 11: Working with Databases 350 Working with relational databases 350 Creating a SQLite database 351 Writing multiple tables to a database 353 Appending data to a table 354 Accessing tables and table fields 354 Learning SQL to query relational databases 357 Fetching query results chunk by chunk 366 Using transactions for consistency 367 Storing data in files to a database 373 Working with NoSQL databases 375 Working with MongoDB 376 Querying data from MongoDB 377 Creating and removing indexes 384 Using Redis 391 Accessing Redis from R 392 Setting and getting values from the Redis server 392 Summary 396 Chapter 12: Data Manipulation 398 Using built-in functions to manipulate data frames 399 Using built-in functions to manipulate data frames 400 Reshaping data frames using reshape2 407 Using SQL to query data frames via the sqldf package 412 Using data.table to manipulate data 417 Using key to access rows 423 Summarizing data by groups 426 [ vii ] Reshaping data.table 428 Using in-place set functions 431 Understanding dynamic scoping of data.table 432 Using dplyr pipelines to manipulate data frames 437 Using rlist to work with nested data structures 446 Summary 451 Chapter 13: High-Performance Computing 452 Understanding code performance issues 453 Measuring code performance 455 Profiling code 462 Profiling code with Rprof 463 Profiling code with profvis 466 Understanding why code can be slow 468 Boosting code performance 470 Using built-in functions 470 Using vectorization 473 Using byte-code compiler 475 Using Intel MKL-powered R distribution 477 Using parallel computing 477 Using parallel computing on Windows 480 Using parallel computing on Linux and MacOS 485 Using Rcpp 486 OpenMP 491 RcppParallel 493 Summary 495 Chapter 14: Web Scraping 496 Looking inside web pages 496 Extracting data from web pages using CSS selectors 503 Learning XPath selectors 506 Analysing HTML code and extracting data 511 Summary 522 Chapter 15: Boosting Productivity 523 Writing R Markdown documents 523 Getting to know markdown 523 Integrating R into Markdown 530 Embedding tables and charts 532 Embedding tables 533 Embedding charts and diagrams 536 Embedding interactive plots 537 [ viii ]

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.