Details

A Data Scientist's Guide to Acquiring, Cleaning, and Managing Data in R


A Data Scientist's Guide to Acquiring, Cleaning, and Managing Data in R


1. Aufl.

von: Samuel E. Buttrey, Lyn R. Whitaker

60,99 €

Verlag: Wiley
Format: PDF
Veröffentl.: 24.10.2017
ISBN/EAN: 9781119080077
Sprache: englisch
Anzahl Seiten: 312

DRM-geschütztes eBook, Sie benötigen z.B. Adobe Digital Editions und eine Adobe ID zum Lesen.

Beschreibungen

<p><b>The only how-to guide offering a unified, systemic approach to acquiring, cleaning, and managing data in R</b></p> <p>Every experienced practitioner knows that preparing data for modeling is a painstaking, time-consuming process. Adding to the difficulty is that most modelers learn the steps involved in cleaning and managing data piecemeal, often on the fly, or they develop their own ad hoc methods. This book helps simplify their task by providing a unified, systematic approach to acquiring, modeling, manipulating, cleaning, and maintaining data in R. </p> <p>Starting with the very basics, data scientists Samuel E. Buttrey and Lyn R. Whitaker walk readers through the entire process. From what data looks like and what it <i>should</i> look like, they progress through all the steps involved in getting data ready for modeling.  They describe best practices for acquiring data from numerous sources; explore key issues in data handling, including text/regular expressions, big data, parallel processing, merging, matching, and checking for duplicates; and outline highly efficient and reliable techniques for documenting data and recordkeeping, including audit trails, getting data back out of R, and more.</p> <ul> <li>The only single-source guide to R data and its preparation, it describes best practices for acquiring, manipulating, cleaning, and maintaining data</li> <li>Begins with the basics and walks readers through all the steps necessary to get data ready for the modeling process</li> <li>Provides expert guidance on how to document the processes described so that they are reproducible</li> <li>Written by seasoned professionals, it provides both introductory and advanced techniques</li> <li>Features case studies with supporting data and R code, hosted on a companion website</li> </ul> <p><i>A Data Scientist's Guide to Acquiring, Cleaning and Managing Data in R</i> is a valuable working resource/bench manual for practitioners who collect and analyze data, lab scientists and research associates of all levels of experience, and graduate-level data mining students.</p>
<p>About the Authors xv</p> <p>Preface xvii</p> <p>Acknowledgments xix</p> <p>About the CompanionWebsite xxi</p> <p><b>1 R 1</b></p> <p>1.1 Introduction 1</p> <p>1.1.1 What Is R? 1</p> <p>1.1.2 Who Uses R and Why? 2</p> <p>1.1.3 Acquiring and Installing R 2</p> <p>1.1.4 Starting and Quitting R 3</p> <p>1.2 Data 3</p> <p>1.2.1 Acquiring Data 3</p> <p>1.2.2 Cleaning Data 4</p> <p>1.2.3 The Goal of Data Cleaning 4</p> <p>1.2.4 Making YourWork Reproducible 5</p> <p>1.3 The Very Basics of R 5</p> <p>1.3.1 Top Ten Quick Facts You Need to Know about R 5</p> <p>1.3.2 Vocabulary 8</p> <p>1.3.3 Calculating and Printing in R 11</p> <p>1.4 Running an R Session 12</p> <p>1.4.1 Where Your Data Is Stored 13</p> <p>1.4.2 Options 13</p> <p>1.4.3 Scripts 14</p> <p>1.4.4 R Packages 14</p> <p>1.4.5 RStudio and Other GUIs 15</p> <p>1.4.6 Locales and Character Sets 15</p> <p>1.5 Getting Help 16</p> <p>1.5.1 At the Command Line 16</p> <p>1.5.2 The Online Manuals 16</p> <p>1.5.3 On the Internet 17</p> <p>1.5.4 Further Reading 17</p> <p>1.6 How to Use This Book 17</p> <p>1.6.1 Syntax and Conventions inThis Book 17</p> <p>1.6.2 The Chapters 18</p> <p><b>2 RData,Part1:Vectors 21</b></p> <p>2.1 Vectors 21</p> <p>2.1.1 Creating Vectors 21</p> <p>2.1.2 Sequences 22</p> <p>2.1.3 Logical Vectors 23</p> <p>2.1.4 Vector Operations 24</p> <p>2.1.5 Names 27</p> <p>2.2 Data Types 27</p> <p>2.2.1 Some Less-Common Data Types 28</p> <p>2.2.2 What Type of Vector IsThis? 28</p> <p>2.2.3 Converting from One Type to Another 29</p> <p>2.3 Subsets of Vectors 31</p> <p>2.3.1 Extracting 31</p> <p>2.3.2 Vectors of Length 0 34</p> <p>2.3.3 Assigning or Replacing Elements of a Vector 35</p> <p>2.4 Missing Data (NA) and Other Special Values 36</p> <p>2.4.1 The Effect of NAs in Expressions 37</p> <p>2.4.2 Identifying and Removing or Replacing NAs 37</p> <p>2.4.3 Indexing with NAs 39</p> <p>2.4.4 NaN and Inf Values 40</p> <p>2.4.5 NULL Values 40</p> <p>2.5 The table() Function 40</p> <p>2.5.1 Two- and Higher-Way Tables 42</p> <p>2.5.2 Operating on Elements of a Table 42</p> <p>2.6 Other Actions on Vectors 45</p> <p>2.6.1 Rounding 45</p> <p>2.6.2 Sorting and Ordering 45</p> <p>2.6.3 Vectors as Sets 46</p> <p>2.6.4 Identifying Duplicates and Matching 47</p> <p>2.6.5 Finding Runs of Duplicate Values 49</p> <p>2.7 Long Vectors and Big Data 50</p> <p>2.8 Chapter Summary and Critical Data Handling Tools 50</p> <p><b>3 R Data, Part 2:More Complicated Structures 53</b></p> <p>3.1 Introduction 53</p> <p>3.2 Matrices 53</p> <p>3.2.1 Extracting and Assigning 54</p> <p>3.2.2 Row and Column Names 56</p> <p>3.2.3 Applying a Function to Rows or Columns 57</p> <p>3.2.4 Missing Values in Matrices 59</p> <p>3.2.5 Using a Matrix Subscript 60</p> <p>3.2.6 Sparse Matrices 61</p> <p>3.2.7 Three- and Higher-Way Arrays 62</p> <p>3.3 Lists 62</p> <p>3.3.1 Extracting and Assigning 64</p> <p>3.3.2 Lists in Practice 65</p> <p>3.4 Data Frames 67</p> <p>3.4.1 Missing Values in Data Frames 69</p> <p>3.4.2 Extracting and Assigning in Data Frames 69</p> <p>3.4.3 ExtractingThings That Aren’tThere 72</p> <p>3.5 Operating on Lists and Data Frames 74</p> <p>3.5.1 Split, Apply, Combine 75</p> <p>3.5.2 All-Numeric Data Frames 77</p> <p>3.5.3 Convenience Functions 78</p> <p>3.5.4 Re-Ordering, De-Duplicating, and Sampling from Data Frames 79</p> <p>3.6 Date and Time Objects 80</p> <p>3.6.1 Formatting Dates 80</p> <p>3.6.2 Common Operations on Date Objects 82</p> <p>3.6.3 Differences between Dates 83</p> <p>3.6.4 Dates and Times 83</p> <p>3.6.5 Creating POSIXt Objects 85</p> <p>3.6.6 Mathematical Functions for Date and Times 86</p> <p>3.6.7 Missing Values in Dates 88</p> <p>3.6.8 Using Apply Functions with Dates and Times 89</p> <p>3.7 Other Actions on Data Frames 90</p> <p>3.7.1 Combining by Rows or Columns 90</p> <p>3.7.2 Merging Data Frames 91</p> <p>3.7.3 Comparing Two Data Frames 94</p> <p>3.7.4 Viewing and Editing Data Frames Interactively 94</p> <p>3.8 Handling Big Data 94</p> <p>3.9 Chapter Summary and Critical Data Handling Tools 96</p> <p><b>4 RData, Part 3: Text and Factors 99</b></p> <p>4.1 Character Data 100</p> <p>4.1.1 The length() and nchar() Functions 100</p> <p>4.1.2 Tab, New-Line, Quote, and Backslash Characters 100</p> <p>4.1.3 The Empty String 101</p> <p>4.1.4 Substrings 102</p> <p>4.1.5 Changing Case and Other Substitutions 103</p> <p>4.2 Converting Numbers into Text 103</p> <p>4.2.2 Scientific Notation 106</p> <p>4.2.3 Discretizing a Numeric Variable 107</p> <p>4.3 Constructing Character Strings: Paste in Action 109</p> <p>4.3.1 Constructing Column Names 109</p> <p>4.3.2 Tabulating Dates by Year and Month or Quarter Labels 111</p> <p>4.3.3 Constructing Unique Keys 112</p> <p>4.3.4 Constructing File and Path Names 112</p> <p>4.4 Regular Expressions 112</p> <p>4.4.1 Types of Regular Expressions 113</p> <p>4.4.2 Tools for Regular Expressions in R 113</p> <p>4.4.3 Special Characters in Regular Expressions 114</p> <p>4.4.4 Examples 114</p> <p>4.4.5 The regexpr() Function and Its Variants 121</p> <p>4.4.6 Using Regular Expressions in Replacement 123</p> <p>4.4.7 Splitting Strings at Regular Expressions 124</p> <p>4.4.8 Regular Expressions versusWildcard Matching 125</p> <p>4.4.9 Common Data Cleaning Tasks Using Regular Expressions 126</p> <p>4.4.10 Documenting and Debugging Regular Expressions 127</p> <p>4.5 UTF-8 and Other Non-ASCII Characters 128</p> <p>4.5.1 Extended ASCII for Latin Alphabets 128</p> <p>4.5.2 Non-Latin Alphabets 129</p> <p>4.5.3 Character and String Encoding in R 130</p> <p>4.6 Factors 131</p> <p>4.6.1 What Is a Factor? 131</p> <p>4.6.2 Factor Levels 132</p> <p>4.6.3 Converting and Combining Factors 134</p> <p>4.6.4 Missing Values in Factors 136</p> <p>4.6.5 Factors in Data Frames 137</p> <p>4.7 R Object Names and Commands as Text 137</p> <p>4.7.1 R Object Names as Text 137</p> <p>4.7.2 R Commands as Text 138</p> <p>4.8 Chapter Summary and Critical Data Handling Tools 140</p> <p><b>5 Writing Functions and Scripts 143</b></p> <p>5.1 Functions 143</p> <p>5.1.1 Function Arguments 144</p> <p>5.1.2 Global versus Local Variables 148</p> <p>5.1.3 Return Values 149</p> <p>5.1.4 Creating and Editing Functions 151</p> <p>5.2 Scripts and Shell Scripts 153</p> <p>5.2.1 Line-by-Line Parsing 155</p> <p>5.3 Error Handling and Debugging 156</p> <p>5.3.1 Debugging Functions 156</p> <p>5.3.2 Issuing Error andWarning Messages 158</p> <p>5.3.3 Catching and Processing Errors 159</p> <p>5.4 Interacting with the Operating System 161</p> <p>5.4.1 File and Directory Handling 162</p> <p>5.4.2 Environment Variables 162</p> <p>5.5 SpeedingThings Up 163</p> <p>5.5.1 Profiling 163</p> <p>5.5.2 Vectorizing Functions 164</p> <p>5.5.3 Other Techniques to Speed Things Up 165</p> <p>5.6 Chapter Summary and Critical Data Handling Tools 167</p> <p>5.6.1 Programming Style 168</p> <p>5.6.2 Common Bugs 169</p> <p>5.6.3 Objects, Classes, and Methods 170</p> <p><b>6 Getting Data into and out of R 171</b></p> <p>6.1 Reading Tabular ASCII Data into Data Frames 171</p> <p>6.1.1 Files with Delimiters 172</p> <p>6.1.2 Column Classes 173</p> <p>6.1.3 Common Pitfalls in Reading Tables 175</p> <p>6.1.4 An Example of When read.table() Fails 177</p> <p>6.1.5 Other Uses of the scan() Function 181</p> <p>6.1.6 Writing Delimited Files 182</p> <p>6.1.7 Reading andWriting Fixed-Width Files 183</p> <p>6.1.8 A Note on End-of-Line Characters 183</p> <p>6.2 Reading Large, Non-Tabular, or Non-ASCII Data 184</p> <p>6.2.1 Opening and Closing Files 184</p> <p>6.2.2 Reading andWriting Lines 185</p> <p>6.2.3 Reading andWriting UTF-8 and Other Encodings 187</p> <p>6.2.4 The Null Character 187</p> <p>6.2.5 Binary Data 188</p> <p>6.2.6 Reading Problem Files in Action 190</p> <p>6.3 Reading Data From Relational Databases 192</p> <p>6.3.1 Connecting to the Database Server 193</p> <p>6.3.2 Introduction to SQL 194</p> <p>6.4 Handling Large Numbers of Input Files 197</p> <p>6.5 Other Formats 200</p> <p>6.5.1 Using the Clipboard 200</p> <p>6.5.2 Reading Data from Spreadsheets 201</p> <p>6.5.3 Reading Data from theWeb 203</p> <p>6.5.4 Reading Data from Other Statistical Packages 208</p> <p>6.6 Reading andWriting R Data Directly 209</p> <p>6.7 Chapter Summary and Critical Data Handling Tools 210</p> <p><b>7 Data Handling in Practice 213</b></p> <p>7.1 Acquiring and Reading Data 213</p> <p>7.2 Cleaning Data 214</p> <p>7.3 Combining Data 216</p> <p>7.3.1 Combining by Row 216</p> <p>7.3.2 Combining by Column 218</p> <p>7.3.3 Merging by Key 218</p> <p>7.4 Transactional Data 219</p> <p>7.4.1 Example of Transactional Data 219</p> <p>7.4.2 Combining Tabular and Transactional Data 221</p> <p>7.5 Preparing Data 225</p> <p>7.6 Documentation and Reproducibility 226</p> <p>7.7 The Role of Judgment 228</p> <p>7.8 Data Cleaning in Action 230</p> <p>7.8.1 Reading and Cleaning BedBath1.csv 231</p> <p>7.8.2 Reading and Cleaning BedBath2.csv 236</p> <p>7.8.3 Combining the BedBath Data Frames 238</p> <p>7.8.4 Reading and Cleaning EnergyUsage.csv 239</p> <p>7.8.5 Merging the BedBath and EnergyUsage Data Frames 242</p> <p>7.9 Chapter Summary and Critical Data Handling Tools 245</p> <p><b>8 Extended Exercise 247</b></p> <p>8.1 Introduction to the Problem 247</p> <p>8.1.1 The Goal 248</p> <p>8.1.2 Modeling Considerations 249</p> <p>8.1.3 Examples ofThings to Check 249</p> <p>8.2 The Data 250</p> <p>8.3 Five Important Fields 252</p> <p>8.4 Loan and Application Portfolios 252</p> <p>8.4.1 Layout of the Beachside Lenders Data 253</p> <p>8.4.2 Layout of theWilson and Sons Data 254</p> <p>8.4.3 Combining the Two Portfolios 254</p> <p>8.5 Scores 256</p> <p>8.5.1 Scores Layout 256</p> <p>8.6 Co-borrower Scores 257</p> <p>8.6.1 Co-borrower Score Examples 258</p> <p>8.7 Updated KScores 259</p> <p>8.7.1 Updated KScores Layout 259</p> <p>8.8 Loans to Be Excluded 260</p> <p>8.8.1 Sample Exclusion File 260</p> <p>8.9 Response Variable 260</p> <p>8.10 Assembling the Final Data Sets 262</p> <p>8.10.1 Final Data Layout 262</p> <p>8.10.2 Concluding Remarks 263</p> <p>A Hints and Pseudocode 265</p> <p>A.1 Loan Portfolios 265</p> <p>A.1.1 Things to Check 266</p> <p>A.2 Scores Database 267</p> <p>A.2.1 Things to Check 268</p> <p>A.3 Co-borrower Scores 269</p> <p>A.3.1 Things to Check 270</p> <p>A.4 Updated KScores 271</p> <p>A.4.1 Things to Check 272</p> <p>A.5 Excluder Files 272</p> <p>A.5.1 Things to Check 272</p> <p>A.6 Payment Matrix 273</p> <p>A.6.1 Things to Check 274</p> <p>A.7 Starting the Modeling Process 275</p> <p>Bibliography 277</p> <p>Index 279</p>
<p><b> SAMUEL E. BUTTREY, PhD</b> is an Associate Professor of Operations Research at the Naval Postgraduate School, Monterey, California, USA. <p><b> LYN R. WHITAKER, PhD</b> is an Associate Professor of Operations Research at the Naval Postgraduate School, Monterey, California, USA.
<p><b> The only how-to guide offering a unified, systemic approach to acquiring, cleaning, and managing data in R </b> <p> Every experienced practitioner knows that preparing data for modeling is a painstaking, time-consuming process. Adding to the difficulty is that most modelers learn the steps involved in cleaning and managing data piecemeal, often on the fly, or they develop their own ad hoc methods. This book helps simplify their task by providing a unified, systematic approach to acquiring, modeling, manipulating, cleaning, and maintaining data in R. <p> Starting with the very basics, data scientists Samuel E. Buttrey and Lyn R. Whitaker walk readers through the entire process. From what data looks like and what it <i>should</i> look like, they progress through all the steps involved in getting data ready for modeling. They describe best practices for acquiring data from numerous sources; explore key issues in data handling, including text/regular expressions, big data, parallel processing, merging, matching, and checking for duplicates; and outline highly efficient and reliable techniques for documenting data and recordkeeping, including audit trails, getting data back out of R, and more. <ul> <li>The only single-source guide to R data and its preparation, it describes best practices for acquiring, manipulating, cleaning, and maintaining data</li> <li>Begins with the basics and walks readers through all the steps necessary to get data ready for the modeling process</li> <li>Provides expert guidance on how to document the processes described so that they are reproducible</li> <li>Written by seasoned professionals, it provides both introductory and advanced techniques</li> <li>Features case studies with supporting data and R code, hosted on a companion website</li> </ul> <br> <p><i> A Data Scientist's Guide to Acquiring, Cleaning, and Managing Data in R</i> is a valuable working resource/bench manual for practitioners who collect and analyze data, lab scientists and research associates of all levels of experience, and graduate-level data mining students.

Diese Produkte könnten Sie auch interessieren:

Modeling Uncertainty
Modeling Uncertainty
von: Moshe Dror, Pierre L'Ecuyer, Ferenc Szidarovszky
PDF ebook
236,81 €
Level Crossing Methods in Stochastic Models
Level Crossing Methods in Stochastic Models
von: Percy H. Brill
PDF ebook
203,29 €
Continuous Bivariate Distributions
Continuous Bivariate Distributions
von: N. Balakrishnan, Chin Diew Lai
PDF ebook
128,39 €